簡體   English   中英

流星蒙哥獲得特定價值

[英]Meteor Mongo getting specific value

我有以下值的集合:

Plans.insert({
  location,
  address,
  date,
  time,
  notes,
  createdAt: new Date(), // current time
  owner: Meteor.userId(),
  username: Meteor.user().username,
  attendees: [
     {
        user: Meteor.user().username;
     },         
     {
        user: Meteor.user().username;
     },
  ],
});

但是我想知道如何獲取數組attendees的特定值。

到目前為止,我已經嘗試過Plans.findOne({ _id: { attendees: [{user: Meteor.user().username},], }}); 但結果不確定。

我還想知道如何獲取每個人的數字值,例如attendees[0]attendees[1]

您需要使用$elemMatch

Plans.findOne({attendees: {$elemMatch: {user: 'ABC'}}};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM