Meteor - collection.find() always returns all fields

后端 未结 2 1163
一向
一向 2020-12-02 19:55

Ran into this (slightly annoying problem) I\'m trying to look up all records in a collection and not show (or show) a specific field (score). This is just an example and not

2条回答
  •  一向
    一向 (楼主)
    2020-12-02 20:20

    First, if you want to control some fields in Collection.find(),you can try to do it this way:

    CollectionName.find({}, {fields: {field:1}});
    

    but it was working only on the server.

    Or try this:

    On the server:

    Meteor.publish("myCollection", function () {
        return SvseTree.find({},{fields: {field:1}});
    });
    

    On the client:

    Meteor.subscribe("myCollection");
    

    then run meteor remove autopublish.

    Second, if you want to get Array of Collection.find(), try to do it: Collection.find().fetch();

提交回复
热议问题