0
var customerData = Customers.findOne(
{'phone': phone},
{ 'restaurants': { $elemMatch: { 'restaurantId': Meteor.userId() } } }
);
我使用$elemMatch
從Restaurants
陣列, 只返回一個對象,但它畢竟是返回array.WHY的所有對象的數組中返回一個對象?如何從對象的MongoDB
是他們只返回一個對象的任何其他方式?
第一個參數是對於查詢,第二個是用於投影(https://docs.mongodb.com/manual/reference/method/db。 collection.findOne /#db.collection.findOne)。您的查詢應該如下所示:'Customers.findOne({'phone':phone,'restaurants.restaurantId':Meteor.userId()});' – Gemmi