【发布时间】:2016-02-14 06:40:41
【问题描述】:
我目前正在使用 mongodb (mongoose)。我的示例文档之一是:
myuser{
_id: 7777...,
money: 1000,
ships:[{
_id: 7777...
name: "myshipname",
products:[{
product_id: 7777....,
quantity: 24
}]
}
}
我的目标是获得特定的产品给定用户 ID、船 id 和产品 ID,结果类似于:{ product_id: 777..,quantity:24}
到目前为止,我找到了一个特定的用户:
findOne(userId,ships:{ $elemMatch: {_id:shipId}})
它从具有userId的用户返回数组ships中带有shipId的船舶信息。但是,我找不到从那艘船上只获得某种产品的方法
【问题讨论】:
标签: mongodb mongoose database nosql