2017-02-20 130 views
0

我有以下值集合:流星蒙戈获得特定值

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]

+0

“我怎么能拿的阵列与会者的具体数值” - 意味着什么?在参加者数组中获取具有特定价值的文档? –

回答

0

您需要使用$elemMatch

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

有没有办法让所有具有这种功能的集合? 'elemMatch'只能检索第一个匹配,但我需要所有适用的。 – DarkTakua

+0

你的意思是关于文件,没有收藏礼仪? –

+0

对不起,我是指文件。 – DarkTakua