Meteor, One to Many Relationship & add field only to client side collection in Publish?

后端 未结 3 388
时光取名叫无心
时光取名叫无心 2020-12-20 05:12

Can anyone see what may be wrong in this code, basically I want to check if a post has been shared by the current logged in user AND add a temporary field to the client side

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 05:49

    Personally, I'd go about this a very different way, by using the $in operator, and keeping an array of postIds or shareIds in the records.

    http://docs.mongodb.org/manual/reference/operator/query/in/

    I find publish functions work the best when they're kept simple, like the following.

    Meteor.publish('posts', function() {
        return Posts.find();
    });
    Meteor.publish('sharedPosts', function(postId) {
        var postRecord = Posts.findOne({_id: postId});
        return Shares.find{{_id: $in: postRecord.shares_array });
    });
    

提交回复
热议问题