2016-07-07 64 views
0
var customerData = Customers.findOne(
    {'phone': phone}, 
    { 'restaurants': { $elemMatch: { 'restaurantId': Meteor.userId() } } } 
); 

我使用$elemMatchRestaurants陣列, 只返回一個對象,但它畢竟是返回array.WHY的所有對象的數組中返回一個對象?如何從對象的MongoDB


是他們只返回一個對象的任何其他方式?

+2

第一個參數是對於查詢,第二個是用於投影(https://docs.mongodb.com/manual/reference/method/db。 collection.findOne /#db.collection.findOne)。您的查詢應該如下所示:'Customers.findOne({'phone':phone,'restaurants.restaurantId':Meteor.userId()});' – Gemmi

回答

0
var customerData = Customers.findOne( 
{'phone': phone`,'restaurants.restaurantId':Meteor.userId()`}).restaurants; 

它必須是可行的解決方案

由於