Mongodb 根据Meteor出版物中找到的条目添加条目
我想根据已经找到的条目为Meteor出版物添加新条目。我有这样的东西:Mongodb 根据Meteor出版物中找到的条目添加条目,mongodb,meteor,meteor-publications,Mongodb,Meteor,Meteor Publications,我想根据已经找到的条目为Meteor出版物添加新条目。我有这样的东西: Meteor.publish("thoughts", function (_id) { Thoughts .find({_id}) .forEach(function(entry) { /* here I want to add new thoughts which should be also published basing o
Meteor.publish("thoughts", function (_id) {
Thoughts
.find({_id})
.forEach(function(entry) {
/* here I want to add new thoughts which should be also published
basing on value of field 'classes' from 'entry' object */
});
this.ready();
});
我怎么办
//编辑
好的,再一次:我的第一个对象看起来像:
{
"_id" : "XCauSwJ4Rm6Ap3yGr",
"classes" : [
"NHfWy7qaygkkt778b" //id of the second object (from the same collection)
],
/* other fields */
}
第二个是:
{
"_id" : "NHfWy7qaygkkt778b",
/* other fields */
}
我想接收两个(作为pararell条目)只知道第一个的\u id
Meteor.publish('thoughts',function(id){
return Thoughts.find({_id:id},{fields:{'classes':1}});
})
通过订阅模板上的相同内容
Template.tmplName.onCreated(function(){
this.autorun(()=>{
this.subscribe('thoughts',id); // id is the one you are giving to publication;
})
})
首先,您的语法是错误的,这不是正确的JS对象。第二,即使在添加括号之后,仍然存在错误-字段到底应该做什么?第三,我觉得我还没有被很好地理解——我又编辑了一遍。我想你只需要上课,如果你不理解,也许你应该对你想要的输出有更多的了解。一个示例输出代码可能再次编辑了我的文章-我想得到两个结果,第一个应该是我粘贴的第一个对象(id
XCauSwJ4Rm6Ap3yGr
),第二个是第二个对象(idNHfWy7qaygkkt778b
)。我希望我现在清楚了…你可以检查一下