Github user pvillard31 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1948#discussion_r124570351
  
    --- Diff: 
nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/GetMongo.java
 ---
    @@ -130,6 +138,31 @@ public ValidationResult validate(final String subject, 
final String value, final
             return propertyDescriptors;
         }
     
    +    private ObjectMapper mapper = new ObjectMapper();
    +
    +    //Turn a list of Mongo result documents into a String representation 
of a JSON array
    +    private String buildBatch(List<Document> documents) throws IOException 
{
    +        List<Map> docs = new ArrayList<>();
    +        for (Document document : documents) {
    +            String asJson = document.toJson();
    +            docs.add(mapper.readValue(asJson, Map.class));
    +        }
    +
    +        return mapper.writeValueAsString(docs);
    +    }
    +
    +    private void writeBatch(String payload, ProcessContext context, 
ProcessSession session) {
    +        FlowFile flowFile = session.create();
    +        flowFile = session.write(flowFile, new OutputStreamCallback() {
    +            @Override
    +            public void process(OutputStream out) throws IOException {
    +                out.write(payload.getBytes("UTF-8"));
    +            }
    +        });
    +        session.getProvenanceReporter().receive(flowFile, 
context.getProperty(URI).getValue());
    --- End diff --
    
    Could you also add the following?
    ````java
    flowFile = session.putAttribute(flowFile, CoreAttributes.MIME_TYPE.key(), 
"application/json");
    ````
    It's not mandatory but will improve UX when viewing flow file content in 
the UI.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to