[英]References in MongoDB / Mongoose / nodejs - parallelization
我想使用nodejs / mongoose在mongoDB中获得引用。
在文档中,我读到有两个选项: 手动引用或DBRef。
由于它们声明了其建议使用的手册参考,因此,我决定以以下方式设置模式:
var schema = new mongoose.Schema({
name : String,
reference : mongoose.Schema.ObjectId
});
我的想法是使用Nimble并并行处理必要的请求。 我想做类似的事情
flow.parallel(functions, function() {
return result;
});
我在其中动态填充函数数组
var functions = []
然后我传递给了敏捷。 (这种SO-问题的种类: JavaScript函数数组 )
您可以使用Mongoose对参考人群的支持来有效地跟踪参考。
var schema = new mongoose.Schema({
name : String,
reference : { type: mongoose.Schema.ObjectId, ref: 'OtherModel' }
});
var MyModel = mongoose.model('MyModel', schema);
MyModel.find().populate('reference').exec(function(err, docs) {...});
在上面的示例中,每个docs
元素的reference
字段都填充了引用的doc。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.