所以我在Angular-Meteor项目中有一个MongoDB集合,我想使用find或findOne
方法返回集合的一个子集(特定的一个项目)。
在这里看一下:
Meteor.publish('eventById', function(eventId){
console.log("The eventId you received is as follows:");
console.log(eventId);
return Events.find({ _id: eventId });
});
我得到的eventId是正确的(看起来像yFzEuDfeLAweiWTEd)。但是,当我控制日志记录实际返回的值时,我有完整的数组,其中包含所有数据块。我只需要基于Id的那个。
我的控制器代码如下所示:
var self = this;
self.currentEventId = $stateParams.id;
self.currentEvent = $scope.$meteorCollection(Events, false).subscribe('eventById', self.currentEventId);
console.log(self.currentEventId);
console.log(self.currentEvent);
记录self.currentEvent
为我提供了与常规Events.find()
电话相同的数组。
事件的架构如下:
{
"title": "Meteor Power Lunch",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean sem nisl, mattis nec odio at, dignissim pharetra elit. Aliquam non ante enim. Praesent quis convallis.",
"date": "04/05/2016",
"imageUrl": "/images/bizz-party.jpg",
"bannerUrl": ""
}
我期望获得的是这些对象中的一个,而Events是这些事件的Mongo集合。我以这种方式通过网址(http://localhost:3000/event/XZGgPvLdf4Kfx5fmr)传递这些项目的生成ID。