native update in Sails with Mongo does not work with ObjectId

前端 未结 3 783
心在旅途
心在旅途 2020-12-21 05:44

I wonder what I am doing wrong.

I use Sailsv0.10 and mongo2.6.0 and want to update an array field (using $push) in a collection via native.

My model:

3条回答
  •  被撕碎了的回忆
    2020-12-21 06:34

    If you want to use native() you can always try the same query directly in your mongo-DB. Because _id is a Object-id you should

    var ObjectId = require('mongodb').ObjectID;
    
     User.native(function (err, collection) {
      collection.update({_id: new ObjectId(anIdVariable)},{$push:{pubs:aPubsVariable}}, function (err) {
    });
    

    You can add the mongo-native-driver to you app with npm install mongodb --save

提交回复
热议问题