Mongoose update without callback

后端 未结 1 624
囚心锁ツ
囚心锁ツ 2020-11-29 10:25

I have a typical schema and model:

var mongoose = require(\'mongoose\');

var userSchema = new mongoose.Schema({
    email: String,
    password: String,
            


        
相关标签:
1条回答
  • 2020-11-29 10:51

    The right way to call update with mongoose is the following:

    User.update(query, update).exec(callback);
    

    This way you will be able to skip callback:

    User.update(query, update).exec();
    

    When you calls

    User.update(query, update)
    

    it returns a query object.

    It's very useful when you querying your database, because you can manipulate with query object before executing it. For example, you can specify a limit for your find query:

    User.find(query).limit(12).exec(callback);
    

    Update uses the same mechanism, though its not so useful there.

    0 讨论(0)
提交回复
热议问题