我需要和mongoose建立自己的关系...稍后我将需要查询,这将显示所有的父母和他们的孩子。另外,所有的孩子都可以成为父母。
这是我的shcema:
var codeSchema = {
code: {
type: String
},
childCode: [{
type: mongoose.Schema.Types.ObjectId,
required: false
}],
parentCode: [{
type: mongoose.Schema.Types.ObjectId,
required: false
}]
};我怎么才能在crete中查询到呢?
发布于 2016-11-21 00:06:27
使用childCode中的ref attr和parentCode.set中的ref attr来指定集合名称,您可以使用填充函数来获取数据。
https://stackoverflow.com/questions/40705651
复制相似问题