亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Problem updating mongodb using mongoose
伊謝爾倫
伊謝爾倫 2017-05-02 09:24:06
0
2
693

Know that mongodb can insert when there is no data and update when there is data by setting the third parameter of update to true.
How to pass in this parameter to the update method encapsulated by mongoose?
The three parameters of update(doc, options, callback) are provided in the mongoose documentation

伊謝爾倫
伊謝爾倫

小伙看你根骨奇佳,潛力無限,來學(xué)PHP伐。

reply all(2)
僅有的幸福

http://mongoosejs.com/docs/ap...

MyModel.update({ name: 'Tobi' }, { ferret: true }, { upsert: true }, function (err, raw) {
if (err) return handleError(err);
console.log('The raw response from Mongo was ', raw);
});

巴扎黑

Set the upsert attribute of the third parameter of the update method to true

Book.update(
// 查詢
{
    name: "The Kite Runner"
},
// 更新
{
    auther: "Khaled Hosseini"
},
// 其他參數(shù)
{
    upsert: true,
}, function(err, doc)
{
    if (err) console.log(err);
    console.log(doc);
});
  • Update the document’s auther attribute when The Kite Runner exists in the database;

  • When there is no The Kite Runner in the database, insert The Kite Runner document;

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