Why my collection.find() does not work in meteor but work in robomongo?

前端 未结 1 1297
北海茫月
北海茫月 2021-01-23 18:22

I have a publication that should return me all users matching an _id array. here it the query:

Meteor.users.find({
            \'_id\': { $in: myArr         


        
相关标签:
1条回答
  • 2021-01-23 18:44

    It looks like you are trying to specify fields in your find, which you can do like this:

    var options = {
      fields: {
        'profile.name': 1,
        'profile.description': 1,
        'profile.picture': 1,
        'profile.website': 1,
        'profile.country': 1
      }
    };
    
    Meteor.users.find({_id: {$in: myArray}}, options);
    

    However, if this is being used in a publish function, I strongly recommend using only top-level fields like so:

    Meteor.users.find({_id: {$in: myArray}}, {fields: {profile: 1}});
    

    For more details on why, please see this question.


    For your second question, you can view the documents returned by a cursor by calling fetch on it. For example:

    console.log(Posts.find({_id: {$in: postIds}}).fetch());
    
    0 讨论(0)
提交回复
热议问题