I am using mongodb 3.6.20, mongoose 5.10.9 and node 14.13.1
The case is the following. I want to insert a complex object to db. The object contains an array of objects where each object also contains an array of objects. These objects given by a client which sets the ids(O do not have power over the client to change it). I want to remove the ids and let mongo drivers to handle them and generate new ones.
what is given:
let obj = {
property1: {
property2: "str",
property3: 3
},
property4 : [{
_id: "a valid mongo id",
property5: "str",
property6: [{
_id: "another valid mongo id",
property7: "str"
}]
}]
}
what I want to provide to insert query:
let obj = {
property1: {
property2: "str",
property3: 3
},
property4 : [{
property5: "str",
property6: [{
property7: "str"
}]
}]
}
I have tried to remove them recursively but the call stack is exceeded.
Is there any clever way I can achieve that? The option {_id: false}
and {id:false}
that I found on mongoose documentation are actually only for the returned documents of a query