【发布时间】:2020-02-02 19:00:30
【问题描述】:
这是我的架构的样子。
const CollectionSchema = new mongoose.Schema({
since: Date,
batch_id: Number,
info: [InfoSchema],
items: [ItemSchema]
});
const ItemSchema = new mongoose.Schema({
name: String,
price: Number,
url: String
});
我正在寻找特定商品名称的 Collection batch_id、Collection info、Item price、Item url。请注意,集合有一个项目数组,我们可以假设项目名称是不同的。下面的查询(我认为)应该返回 Collection info + batch_id 用于包含名称为“lego”的任何项目的集合。
Collections.find(
{ "items.name": 'lego' },
{ info: 1, batch_id: 1 }
)
.where("since")
.gt(minutesAgo)
我想在回复中包含商品价格和商品网址。我将如何更改 find() 调用以返回该数据?同样,添加项目:1 将添加所有项目(但我正在寻找匹配项目的价格和网址)。
【问题讨论】: