我来自SQL背景,并且发现很难用mongoose构建查询。
我有一个如下所示的组架构:
var groupSchema = new Schema({
title:{type:String, index:true, unique: true, required:true, lowercase:true}
});
以及引用groupSchema
用户架构:
var userSchema = new Schema({
//Other datas
group: [{type: Schema.Types.ObjectId, ref: 'Group'}],
});
文件架构:
var documentSchema = new Schema({
ownerId:{type:Schema.Types.ObjectId, required: true, ref:"User"},
group:{ type:Schema.Types.ObjectId, ref:"Group", required:true},
});
我想fetch all group data and populate them with the documents that belong to that group
。我尝试使用populate查询,但它不起作用