Closed
Description
hi, i am having trouble starting a counter n
at a specified number and then increasing by 1 using findOneAndUpdate
and upsert: true
.
var RefSchema = new Schema({
_id: {type: String, default: 'refs'},
n: {type: Number, default: 776}
});
...
var query = {_id: 'refs'};
var update = {$inc: {n: 1}};
var options = {upsert: true, 'new': true};
// this will create the doc if it doesn't exist the first time,
// it should use the default value from the schema instead of the value passed to $inc
RefSchema.findOneAndUpdate(query, update, options, function (err, doc) {
console.log(doc.n); // is 1 but i expect to see 776
});
what i expect is the creation of a document with the n
property starting at 776
and then increasing from that value.
Metadata
Metadata
Assignees
Labels
No labels