How to perform an upsert in Mongoose looking for an embedded document?

前端 未结 2 624
清歌不尽
清歌不尽 2021-01-21 00:33
SocialProfileSchema = new mongoose.Schema
  source:
    type: String
    enum: [\'twitter\',\'facebook\']
    lowercase: true
  user_id: String
  profile_url: String
  p         


        
2条回答
  •  Happy的楠姐
    2021-01-21 00:52

    Here's an example of how you can do an update if exists, otherwise insert:

    Arguments for update are: findQuery, data, queryOptions, onComplete

    var update = { data: "1", expires: 300 };
    that.update({ session_id: sid }, { $set: update }, { upsert: true }, function(err, data) {
      callback.apply(this, arguments);
    });
    

提交回复
热议问题