[英]References in MongoDB / Mongoose / nodejs - parallelization
I want to get references in mongoDB using nodejs/mongoose. 我想使用nodejs / mongoose在mongoDB中获得引用。
In the documentation I read that there are two options: Manual References or DBRefs. 在文档中,我读到有两个选项: 手动引用或DBRef。
Since they state, its recommended to use Manual References, I decided to set up a schema in the following way: 由于它们声明了其建议使用的手册参考,因此,我决定以以下方式设置模式:
var schema = new mongoose.Schema({
name : String,
reference : mongoose.Schema.ObjectId
});
My Idea was to use Nimble and parallelize the necessary requests. 我的想法是使用Nimble并并行处理必要的请求。 I wanted to do something like
我想做类似的事情
flow.parallel(functions, function() {
return result;
});
where I dynamically fill an array of functions 我在其中动态填充函数数组
var functions = []
which I pass then to nimble. 然后我传递给了敏捷。 (kind of this SO-question: Javascript Array of Functions )
(这种SO-问题的种类: JavaScript函数数组 )
You can use Mongoose's support for reference population to efficiently follow references. 您可以使用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) {...});
In the above example, the reference
field of each docs
element gets populated with referenced doc. 在上面的示例中,每个
docs
元素的reference
字段都填充了引用的doc。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.