【发布时间】:2015-12-18 02:51:53
【问题描述】:
我正在使用meteor.js。我有三个收藏板、类别、用户。
Boards :
{
"_id": ObjectId("su873u498i0900909sd"),
"locked": NumberInt(0),
"board_name": "Legends",
"description": "legends of the world",
"cat_id": ObjectId("su873u498i0900909sd"),
"cost": NumberInt(1),
"image": "1389249002691_indexhj.jpeg",
"creator": ObjectId("52ce317994acdcee0fadc90c")
}
categories:
{
"_id": ObjectId("su873u498i0900909sd"),
"user_id": ObjectId("su873u498i0900909sd"),
catname:"hjjj"
}
users:
{
"_id":ObjectId(55acec2687fe55f12ded5b4a),
"username" :"mariya"
}
由此我想在用户集合中获取用户名,该用户名在类别集合中使用 user_id 字段引用,其中类别集合在板集合中使用 cat_id 引用。这就是试图得到它的方式。
Boards.find({_id:"ObjectId(55acec2687fe55f12ded5b4a)"},function(res){
if(res){
categories.find({_id:res.cat_id},function(res1){
if(res1){
users.find({_id:res.user_id},function(res3){
res.send(res3)
})
})
})
因为在流星中使用猫鼬会影响性能,所以我不能使用填充方法。那么,除了上述方法之外,还有其他方法可以实现结果吗?
【问题讨论】:
-
joins 还没有真正得到官方支持,但是有一些包可以帮助我们使用,例如:atmospherejs.com/reywood/publish-composite
-
感谢马克 Uretsky。让我试试。