我想获得包含所有打折产品的目录。Mongodb:汇总数据并在每个元素上应用函数
2个文件:
/* Catalog schema */
{
Catalog: {
products: [{
type: ObjectId,
ref: 'Product'
}],
discount: {
global: { type: Number, default: 0 },
categories: [{
codeCategory: String,
discount: Number
}]
}
}
/* Product schema */
{
reference: {
type: String,
index: true,
unique: true
},
url_photo: {
type: String,
default: 'http://localhost:3001/app/img/no-picture.jpg'
},
category: {
type: ObjectId,
ref: 'Category'
},
short_description: String,
long_description: String,
price: Number,
information: String
}
的折扣适用于从目录中的每个产品,我怎么能做出蒙戈查询目录中得到所有产品与应用的折扣?
我可以直接查询有这个结果吗?
我已经检查了聚合,但我是新的,我看不到我怎么做到这一点。
谢谢
凡存储的文件?在同一个集合中?您使用了哪些驱动程序,例如猫鼬,pymongo等?如果我不得不猜测,我会说你正在用猫鼬做一个Node应用程序。 – dasdachs
目录,产品和类别是分离的集合。我正在使用猫鼬。你猜对了,它是节点应用程序。 – stephane
为什么在Catalog Schema中有两个'discounts'? – dasdachs