mkiran
March 9, 2021, 3:59pm
1
When I try insert a date filed in MongoDB it is inserting as null.
actually the date should insert like as follows
"createdDate": {
"$date": "2021-03-09T09:04:52.794Z"
},
but it is inserting as
"createdDate":null
Can some one help me to insert a date filed into MongoDB.
Thanks in Advance.
Hello, can you share your current workflow?
mkiran
March 9, 2021, 4:14pm
3
Here is the workflow
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
160,
280
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "createdDate",
"value": "2019-10-07T18:30:00.000Z"
},
{
"name": "name",
"value": "Adam Smith"
}
]
},
"options": {}
},
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
310,
280
]
},
{
"parameters": {
"operation": "insert",
"collection": "User",
"fields": "name,createdDate"
},
"name": "MongoDB",
"type": "n8n-nodes-base.mongoDb",
"typeVersion": 1,
"position": [
510,
280
],
"credentials": {
"mongoDb": "mongo-cred"
}
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "MongoDB",
"type": "main",
"index": 0
}
]
]
}
}
}
It’s working just fine for me. Not sure what might be happening there. Is the date field nested?
Can you share your schema?
mkiran
March 9, 2021, 4:35pm
5
The schema is already defined using some other application. And in the mongoDB schema definition, the createdDate property datatype defined as Date type. So its getting inserting as null.
mkiran
March 9, 2021, 4:53pm
6
Hi @RicardoE105 actually the date should insert like as follows
"createdDate": {
"$date": "2021-03-09T09:04:52.794Z"
},
but it is inserting as
"createdDate":null
Ahh yes, I tested with a string type. That is why it worked for me. Checking again
Ahh yes, had to make some changes to make work. Will send the PR today. We will try to add to the next released.
Ok, added a new option field called “Date Fields”. Set the the Date Fields and it’s gonna be set to a instance of Date. Can you test it locally and provide feedback?
https://github.com/n8n-io/n8n/pull/1529
jan
March 12, 2021, 12:06pm
11
Got released with [email protected]
mkiran
March 12, 2021, 12:30pm
12
Thanks a lot @jan for prompt response