We are trying to use MongoDB node to store timeseries data external to Losant.
But keep on getting error from external DB related to timestamp format:
“timestamp” is defined as time type attribute in the collection.
Have tried a number of combination but doesnt seem to work as well as separate json object.
Is it possible to get some feedback on the usage of MongoDB node in this case?
Thanks!
Hi @Alok_Singh1 and welcome to the Losant forums!
I’m taking a look at this and will get back with you shortly.
What is the data type for the property you’re trying to report as a date?
Do you mind posting your collection’s schema (or at least the part relevant to this property), making sure to remove any potentially sensitive information? If you’d prefer, you can DM it to me.
Thanks @Sebastian_Turner for looking into this.
Here is my sample test schema before we create an actual one:
From MongoDB Shell
Atlas atlas-hiciep-shard-0 [primary] test> db.createCollection( "weather", { timeseries: { timeField: "timestamp", metaField: "metadata", granularity: "hours" } })
{ ok: 1 }
Atlas atlas-hiciep-shard-0 [primary] test> db.weather.insertOne( { "metadata": { "sensorId": 5578, "type": "temperature" }, "timestamp": new Date(), "temp": 16 })
{
acknowledged: true,
insertedId: ObjectId("64431a3c6914853957b81508")
}
@Alok_Singh1 , thanks for your patience while we investigated this issue.
We’ve identified an issue with how dates are parsed when entered into the MongoDB Node. While our engineering team works on a fix, here’s a workaround:
-
Use a Mutate Node to create an object containing two new values:
-
The first will be everything in your JSON object other than the timestamp
field, with the “Treat value as JSON” box checked. Set a destination path (in this example, mongoDbInsert
) .
-
The next will be your timestamp
field. Enter the string value in the Value Template, and leave “Treat value as JSON” unchecked. Set a destination path (in this example, mongoDbInsert.timestamp.$date
) .
- In your MongoDB Node, under Document(s) Argument, set the Value Type to Payload Path and the Argument Value to the destination you specified in the Mutate Node (in this example,
mongoDbInsert
) .
Give this a try and let us know how it goes. I’ll follow up on this thread once I have an update on the fix for the MongoDB node.
Thanks @Sebastian_Turner. I have checked the workaround and could insert in Mongodb timeseries DB.