【问题标题】:how to return one object from array of object mongodb如何从对象mongodb数组中返回一个对象
【发布时间】:2016-07-07 11:25:50
【问题描述】:
var customerData = Customers.findOne(
   {'phone': phone}, 
   { 'restaurants': { $elemMatch: { 'restaurantId': Meteor.userId() } } }
);

我正在使用$elemMatchRestaurants 数组中只返回一个对象, 但它仍然返回数组的所有对象。为什么?


他们还有其他方式只返回一个对象吗?

【问题讨论】:

标签: mongodb meteor mongoose mongodb-query database


【解决方案1】:
var customerData = Customers.findOne(  
{'phone': phone`,'restaurants.restaurantId':Meteor.userId()`}).restaurants;

必须是可行的解决方案

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-15
    • 2017-12-14
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 2022-01-13
    • 2018-12-11
    相关资源
    最近更新 更多