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