Meteor, MongoDB get part of array through subscription

后端 未结 2 385
花落未央
花落未央 2021-01-14 03:54

I have a question about how to just get a certain element of an array using MongoDB and MeteorJS. I have the following schema for the user document:

    bank         


        
2条回答
  •  星月不相逢
    2021-01-14 04:08

    It looks like you're just missing the "fields" specifier in your "userBankAdvanced" publish function. I wrote a test in meteorpad using your example and it seems to work fine. The bank id is hardcoded for simplicity there.

    So instead of

    return Meteor.users.find({_id:this.userId,"bankList.id": bankId}, {'bankList.$': 1});
    

    try using

    return Meteor.users.find({_id:this.userId,"bankList.id": bankId}, {fields: {'bankList.$': 1}});
    

提交回复
热议问题