[英]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.