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

の配列から一つのオブジェクトを返すには?


1つのオブジェクトだけを返す他の方法はありますか?

+2

実行可能な解決策でなければならない第二の突起(https://docs.mongodb.com/manual/reference/method/dbするためのものである、クエリのためのものです。 collection.findOne /#db.collection.findOne)。あなたのクエリは次のようになります: 'Customers.findOne({'phone':電話、 'restaurants.restaurantId':Meteor.userId()}))' – Gemmi

答えて

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

それは最初のパラメータ

おかげ

関連する問題