mongodb - Mongoose update parameter is empty
黄舟
黄舟 2017-05-02 09:25:20
0
2
655

Initialization ' update = {'$inc': {"Prodects.$.price": 1}},'

but cannot be passed in in the update parameter, the result is '$inc': {} ,

Version number

node v6.6.0 
"mongoose": "^4.7.5",
MongoDB shell version v3.4.0

app.js

#开启调试模式
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, but declares 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

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
阿神

A summary of problems encountered by Mongoose

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 are available

 Model.collection.update(conditions, update, function(err, result){
          res.send(result)
        });
漂亮男人

Mongoose’s documentation is a bit too concise, so there are many usage problems.

I hope everyone can work together to compile some good Chinese documents for Mongoose.

Love MongoDB! Have Fun!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template