Initialization‘ update = {‘$inc’: {“Prodects.$.price”: 1}},’
But cannot be passed inUpdate parameterThe result is‘$inc’: {},
Version number
node v6.6.0
"mongoose": "^4.7.5",
MongoDB shell version v3.4.0
app.js
# Turn on debug mode
var mongoose = require('mongoose').set('debug', true); ;
router.js
router.get('/test', function(req, res, next){
var conditions = {"Prodects.id": "2"},
update = {'$inc': {"Prodects.$.price": 1}},
options = {upsert:true};
CartModel.update(conditions, update, options, function(err) {
});
});
The terminal shows that the data of the second parameter is empty, butDeclares an object
hotnode node process restarted
{ '$inc': { 'Prodects.$.price': 1 } }
Mongoose: carts.update({ 'Prodects.id': '2' }, { '$inc': {}, '$setOnInsert': { __v: 0 } }, { upsert: true })
The second parameter-‘$inc’: {}, initialization‘ update = {‘$inc’: {“Prodects.$.price”: 1}},’
So that the data in the database cannot be updated
Summary of Mongoose’s Problems
var conditions = {"Prodects.id": "2"}, update = {'$inc': {"Prodects.$.price": 1}}, options = {upsert:true}; CartModel.update(conditions, update, options, function(err) { }); });
Print results
{ '$inc': { 'Prodects.$.price': 1 } } Mongoose: carts.update({ 'Prodects.id': '2' }, { '$inc': {}, '$setOnInsert': { __v: 0 } }, { upsert: true })
The following methods can be used
Model.collection.update(conditions, update, function(err, result){ res.send(result) });