This is my code:
if (Type.isArray(docs) && docs.length > 0) {
promises.push(
new Promise(function promise(resolve, reject) {
that.model.collection.bulkWrite(
docs.map(item => {
that.modify(item);
return {
updateOne: {
filter: {
id: item.id
},
update: item,
upsert: true
},
}
}),
(err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
}
)
})
)
}
Basically I get a large array of items, if they exist in the db, I update them, if they don't exist, i create them. I'm doing all this in NodeJS btw, if the code isn't apparent :D Problem is, with my old implementation, my mongo document had different property types, Int32, String, Date, Boolean, you name it! But with bulkWrite they all somehow get converted to String, except booleans which stay as Boolean type.
Also, the first time i execute the new implementation, it doesnt add update existing items, but duplicates them, because the "id" is not, for example 2456 Int32, but its "2456" String
Google yielded no results, or im not inputting the correct search text.
Thanks for your help!
via SephirothMK
No comments:
Post a Comment