通过检查另一个 collection 中的条件从 collection 中获取数据
fetch data from a collection by checking a condition in another collection
我正在研究 angular-meteor。
在我的数据库中有两个 collection,即订阅和学校。
订阅:
[
{
"_id" : "9qAcc86yhG7hSxejL",
"school" : {
"_id" : "uz7rMGXJwn566GhBg"
},
"wrk_status":"completed"
},
{
"_id" : "9qAcc86yhG7hSxejL",
"school" : {
"_id" : "uz7oMGXJwn566GhBg"
},
"wrk_status":"pending"
},
{
"_id" : "9qAcc86yhG7hSxejL",
"school" : {
"_id" : "uz7pMGXJwn566GhBg"
},
"wrk_status":"completed"
}]
学校:
[
{
"_id" : "uz7rMGXJwn566GhBg",
"name" : "The Oxford School",
"address" : "Trivandrum",
"status" : "new",
},
{
"_id" : "uz7oMGXJwn566GhBg",
"name" : "The School",
"address" : "Trivandrum",
"status" : "new",
},
{
"_id" : "uz7pMGXJwn566GhBg",
"name" : "The new School",
"address" : "Trivandrum",
"status" : "new",
}]
所以我想从学校 collection 获取学校的名称、地址和状态,其中 wrk_status 在订阅 collections 已完成。
所以一开始我想订阅订阅 collection 并在 wrk_status 完成的地方获取 school._id 然后订阅学校 collection 以列出学校的详细信息 school._id
制作学校词典
var sch_dict = {};
shools.forEach(function(sch) {
sch_dict[sch._id] = sch
});
var result = []
subscriptions.forEach(function(sub) {
if (sub.wrk_status = 'completed') {
result.push(sch_id[sub.school._id]);
}
})
您可以为此使用 reywood:publish-composite 包。
提供了一种灵活的方式来使用反应式联接从各种集合中发布一组相关文档。这使得一次发布整个文档树变得容易。已发布的合集是被动的,将在制作 additions/changes/deletions 时更新。
这里是link
我正在研究 angular-meteor。 在我的数据库中有两个 collection,即订阅和学校。 订阅:
[
{
"_id" : "9qAcc86yhG7hSxejL",
"school" : {
"_id" : "uz7rMGXJwn566GhBg"
},
"wrk_status":"completed"
},
{
"_id" : "9qAcc86yhG7hSxejL",
"school" : {
"_id" : "uz7oMGXJwn566GhBg"
},
"wrk_status":"pending"
},
{
"_id" : "9qAcc86yhG7hSxejL",
"school" : {
"_id" : "uz7pMGXJwn566GhBg"
},
"wrk_status":"completed"
}]
学校:
[
{
"_id" : "uz7rMGXJwn566GhBg",
"name" : "The Oxford School",
"address" : "Trivandrum",
"status" : "new",
},
{
"_id" : "uz7oMGXJwn566GhBg",
"name" : "The School",
"address" : "Trivandrum",
"status" : "new",
},
{
"_id" : "uz7pMGXJwn566GhBg",
"name" : "The new School",
"address" : "Trivandrum",
"status" : "new",
}]
所以我想从学校 collection 获取学校的名称、地址和状态,其中 wrk_status 在订阅 collections 已完成。 所以一开始我想订阅订阅 collection 并在 wrk_status 完成的地方获取 school._id 然后订阅学校 collection 以列出学校的详细信息 school._id
制作学校词典
var sch_dict = {};
shools.forEach(function(sch) {
sch_dict[sch._id] = sch
});
var result = []
subscriptions.forEach(function(sub) {
if (sub.wrk_status = 'completed') {
result.push(sch_id[sub.school._id]);
}
})
您可以为此使用 reywood:publish-composite 包。
提供了一种灵活的方式来使用反应式联接从各种集合中发布一组相关文档。这使得一次发布整个文档树变得容易。已发布的合集是被动的,将在制作 additions/changes/deletions 时更新。
这里是link