Mongodb 如何在Mongoose中执行upsert以查找嵌入的文档?
这就是我的模式。在Mongodb 如何在Mongoose中执行upsert以查找嵌入的文档?,mongodb,node.js,mongoose,Mongodb,Node.js,Mongoose,这就是我的模式。在SocialProfileSchema中检查特定的用户id,然后执行upsert似乎是一项庞大的任务。有可能吗 dbref怎么样?它将允许您直接访问SocialProfiles,而不必通过一堆嵌入对象进行循环 以下是一个示例,说明如何在存在更新时执行更新,否则请插入: 更新的参数有:findQuery、data、queryOptions、onComplete SocialProfileSchema = new mongoose.Schema source: type
SocialProfileSchema
中检查特定的用户id
,然后执行upsert似乎是一项庞大的任务。有可能吗 dbref怎么样?它将允许您直接访问SocialProfiles,而不必通过一堆嵌入对象进行循环
以下是一个示例,说明如何在存在更新时执行更新,否则请插入: 更新的参数有:findQuery、data、queryOptions、onComplete
SocialProfileSchema = new mongoose.Schema
source:
type: String
enum: ['twitter','facebook']
lowercase: true
user_id: String
profile_url: String
primary:
type: Boolean
default: true
added_on:
type: String
default: Math.round(new Date().getTime()/1000.0)
UserProfileSchema = new mongoose.Schema
socialProfiles: [SocialProfileSchema]
added_on:
type: String
default: Math.round(new Date().getTime()/1000.0)
仅供参考,您不需要使用callback.apply(…);您可以简单地使用回调(…)。
var update = { data: "1", expires: 300 };
that.update({ session_id: sid }, { $set: update }, { upsert: true }, function(err, data) {
callback.apply(this, arguments);
});