【发布时间】:2016-07-07 11:25:50
【问题描述】:
var customerData = Customers.findOne(
{'phone': phone},
{ 'restaurants': { $elemMatch: { 'restaurantId': Meteor.userId() } } }
);
我正在使用$elemMatch 从Restaurants 数组中只返回一个对象,
但它仍然返回数组的所有对象。为什么?
他们还有其他方式只返回一个对象吗?
【问题讨论】:
-
第一个参数用于查询,第二个用于投影(docs.mongodb.com/manual/reference/method/db.collection.findOne/…)。您的查询应如下所示:
Customers.findOne({'phone':phone, 'restaurants.restaurantId' : Meteor.userId()});
标签: mongodb meteor mongoose mongodb-query database