search

Home  >  Q&A  >  body text

mongodb - Mongoose 更新参数为空

初始化 ' update = {'$inc': {"Prodects.$.price": 1}},'

但无法传入update 参数中, 结果为'$inc': {} ,

版本号

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) {
      });
});

终端显示第二个参数的数据为空, 但是声明的是一个对象

hotnode  node process restarted

{ '$inc': { 'Prodects.$.price': 1 } }
Mongoose: carts.update({ 'Prodects.id': '2' }, { '$inc': {}, '$setOnInsert': { __v: 0 } }, { upsert: true })

第二个参数 ---- '$inc': {} , 初始化 ' update = {'$inc': {"Prodects.$.price": 1}},'

以至于无法更新数据库中的数据

黄舟黄舟2757 days ago645

reply all(2)I'll reply

  • 阿神

    阿神2017-05-02 09:27:20

    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)
            });

    reply
    0
  • 漂亮男人

    漂亮男人2017-05-02 09:27:20

    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!

    reply
    0
  • Cancelreply