Support Questions

Find answers, ask questions, and share your expertise

Date Value and Format issue for MONGODB data using NIFI

avatar
New Contributor

When I use the GETMONGO processor to read source data from MongoDB with the output format set to Standard JSON, it converts the original date value to the local timestamp. However, when using the Extended JSON format, the original date value appears but in a different format.

I need one of the following solutions:

1. Original date value in Standard JSON format: The date should appear as "createdAt": "2012-08-27T22:32:56Z".
2. Date format in Extended JSON: The date should appear as {"createdAt": "2012-08-27T22:32:56Z"}.
3. Transformation: Convert the Extended JSON format from "createdAt": {"$date": "2012-08-27T22:32:56Z"} to {"createdAt": "2012-08-27T22:32:56Z"}.

Here are examples of the outputs:

**Standard JSON output:**

[
{
"_id": "629f3a565f65e119263fa79e",
"id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"firstName": "kelly",
"createdAt": "2012-08-28T10:32:56Z",
"modifiedAt": "2024-07-01T18:17:29Z",
"suspended": false,
"linkedAccounts": [
{
"accountNumber": "100000000",
"accountType": "SAV",
"linkedAt": "2012-08-28T10:36:58Z"
}
],
"auth0Id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"gender": "FEMALE"
}
]
**Extended JSON output:**

[
{
"_id": {"$oid": "629f3a565f65e119263fa79e"},
"id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"firstName": "kelly",
"createdAt": {"$date": "2012-08-27T22:32:56Z"},
"modifiedAt": {"$date": "2024-07-01T06:17:29.467Z"},
"suspended": false,
"linkedAccounts": [
{
"accountNumber": "100000000",
"accountType": "SAV",
"linkedAt": {"$date": "2012-08-27T22:36:58Z"}
}
],
"auth0Id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"gender": "FEMALE"
}
]
Thanks for the help.

1 REPLY 1

avatar
New Contributor

Hello,


@kelly01 wrote:

When I use the GETMONGO processor to read source data from MongoDB with the output format set to Standard JSON, it converts the original date value to the local timestamp. However, when using the Extended JSON format, the original date value appears but in a different format.

I need one of the following solutions:

1. Original date value in Standard JSON format: The date should appear as "createdAt": "2012-08-27T22:32:56Z".
2. Date format in Extended JSON: The date should appear as {"createdAt": "2012-08-27T22:32:56Z"}.
3. Transformation: Convert the Extended JSON format from "createdAt": {"$date": "2012-08-27T22:32:56Z"} to {"createdAt": "2012-08-27T22:32:56Z"}.

Here are examples of the outputs:

**Standard JSON output:**

[
{
"_id": "629f3a565f65e119263fa79e",
"id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"firstName": "kelly",
"createdAt": "2012-08-28T10:32:56Z",
"modifiedAt": "2024-07-01T18:17:29Z",
"suspended": false,
"linkedAccounts": [
{
"accountNumber": "100000000",
"accountType": "SAV",
"linkedAt": "2012-08-28T10:36:58Z"
}
],
"auth0Id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"gender": "FEMALE"
}
]
**Extended JSON output:**

[
{
"_id": {"$oid": "629f3a565f65e119263fa79e"},
"id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"firstName": "kelly",
"createdAt": {"$date": "2012-08-27T22:32:56Z"},
"modifiedAt": {"$date": "2024-07-01T06:17:29.467Z"},
"suspended": false,
"linkedAccounts": [
{
"accountNumber": "100000000",
"accountType": "SAV",
"linkedAt": {"$date": "2012-08-27T22:36:58Z"}
}
],
"auth0Id": "46dd1621-910f-4eb6-91a0-5ae609a77b10",
"gender": "FEMALE"
}
]
Thanks for the help.


Your data is coming out in a weird format.

You want the dates to look normal, not like a computer wrote them.

Here's the deal:

  • The easy way: Use a tool to fix the weird date format after you get the data.
  • The complicated way: Change how you get the data so the dates come out normal from the start.

Let me know if you want to try either of these!