Hello,

Right now AttributesToJson does treat everything as strings. I remember a
previous discussion about adding support for different types, but I can't
find a JIRA that references this.

One option to work around this could be to use ReplaceText to construct the
JSON, instead of AttributesToJson. You could set the Replacement Value
property to something like:

{
  "dataSourceId" : "${datasource}",
  "filename" : "${filename}",
  "sent_date" : ${sent_date},
  "uuid" : "${uuid}",
  "originalSource" : "${originalsource}"
}

Of course using the appropriate attribute names.

Another option is that in the upcoming 0.7.0 release, there is a new
processor to transform JSON using JOLT. With that processor you may be able
to take the output of AttributesToJson and apply a transform that converts
the date field to remove the quotes.

Hope that helps.

-Bryan

On Mon, Jun 27, 2016 at 8:16 AM, Asanka Sanjaya Herath <[email protected]>
wrote:

> I'm trying to insert a flow file to MongoDb which has a date record as an
> attribute. First I sent that flow file through an attribute to JSON
> processor, so that all attributes are now converted to a Json document in
> flow file body. When I insert that flow file to Mongodb using PutMongo
> processor, it saves the "sent_date" attribute as a String. I want this to
> be saved as an ISO date object.
>
> My flow file looked like this.
>
> {
>   "dataSourceId" : "xxxx",
>   "filename" : "979f7bc5-a395-4396-9625-69fdb2c806c6",
>   "sent_date" : "Mon Jan 18 04:50:50 IST 2016",
>   "uuid" : "77a5ef56-8b23-40ee-93b5-78c6323e0e1c",
>   "originalSource" : "ImportedZip"
> }
>
> Then I prepend "ISODate" to "sent_date" attribute using another processor.
> So now my flow file content looks like this.
> {
>   "dataSourceId" : "xxxx",
>   "filename" : "979f7bc5-a395-4396-9625-69fdb2c806c6",
>   "sent_date" : "ISODate('Mon Jan 18 04:50:50 IST 2016')",
>   "uuid" : "77a5ef56-8b23-40ee-93b5-78c6323e0e1c",
>   "originalSource" : "ImportedZip"
> }
>
> But still It is saved as a string in MongoDB, because of the double
> quotation marks. Is there a way to remove those double quotation marks when
> convert using AttributeToJson processor?
>
> Any help is appreciated.
>
> --
> Thanks,
> Regards,
> ASH
>

Reply via email to