null
is a valid _id
value in MongoDB, so if you don’t want it used in new docs you must ensure that a null
value is replaced with a new ObjectID
in query
:
var query = {_id: plcy._id};
if (!query._id) {
query._id = new mongoose.mongo.ObjectID();
}
// the rest stays the same...