You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$inc method store previous value and save all together, output should be:
Mongoose: users.updateOne({ _id: new ObjectId("640e547132b7729ceb60d6d6") }, { '$inc': { coins: 3000 } }, { session: null })
The text was updated successfully, but these errors were encountered:
I am able to reproduce on 7.0.4, but as floatingmess06 pointed out if you do a save operation beforehand it works fine.
constmongoose=require('mongoose');mongoose.set('debug',true);consttestSchema=newmongoose.Schema({coins: Number});constTest=mongoose.model('Test',testSchema);asyncfunctionrun(){awaitmongoose.connect('mongodb://localhost:27017');awaitmongoose.connection.dropDatabase();awaitTest.create({coins: 0});constdoc=awaitTest.findOne();doc.$inc('coins',1000);console.log('what is doc',doc);doc.$inc('coins',2000);console.log('what is doc',doc);awaitdoc.save();console.log('doc after save',doc);console.log(awaitTest.findOne());console.log('done');}run();
Prerequisites
Mongoose version
6.7.2
Node.js version
v16.0.0
MongoDB server version
4.4.5
Typescript version (if applicable)
No response
Description
$inc method locally saves all data, but sends to mongoose the last one
Steps to Reproduce
Execute $inc method twice or more times
Expected Behavior
$inc method store previous value and save all together, output should be:
Mongoose: users.updateOne({ _id: new ObjectId("640e547132b7729ceb60d6d6") }, { '$inc': { coins: 3000 } }, { session: null })
The text was updated successfully, but these errors were encountered: