'When upsert a document in mongodb(nodejs), and upsertedCount > 0, how can I make the upsertedId not null?
When I use updateOne({ _id: profile._id }, {$set: profile}, { upsert: true }), the returned result is
result= {
acknowledged: true,
modifiedCount: 0,
upsertedId: null,
upsertedCount: 1,
matchedCount: 0
}
And it inserts a document with _id=null, I want to use the auto-generated _id but don't want it to be null, what do I need to do?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
