我是 mongo 数据库的新手,正在创建使用它的 web 应用程序
db.element.aggregate([{
"$match": {
"versions.branch": branch
}
}, {
"$match": {
"$or": [{
"doctype": "10921"
}, {
"doctype": "10926"
}, {
"doctype": "10943"
}, {
"doctype": "10945"
}, {
"doctype": "13162"
}, {
"doctype": "1521"
}, {
"doctype": "15281"
}, {
"doctype": "15282"
}, {
"doctype": "15283"
}, {
"doctype": "15284"
}, {
"doctype": "15291"
}, {
"doctype": "15372"
}, {
"doctype": "15431"
}, {
"doctype": "1545"
}, {
"doctype": "1550"
}, {
"doctype": "1551"
}, {
"doctype": "1555"
}, {
"doctype": "15514"
}, {
"doctype": "15516"
}, {
"doctype": "15517"
}, {
"doctype": "15518"
}, {
"doctype": "15519"
}, {
"doctype": "1553"
}, {
"doctype": "15542"
}, {
"doctype": "17402"
}, {
"doctype": "19009"
}, {
"doctype": "19055"
}, {
"doctype": "19073"
}, {
"doctype": "19082"
}, {
"doctype": "19083"
}, {
"doctype": "19812"
}, {
"doctype": "2134"
}, {
"doctype": "2400"
}, {
"doctype": "2401"
}]
}
}, {
"$match": {
"prefix": {
"$ne": "500"
}
}
}, {
"$sort": {
"id": 1
}
}, {
"$unwind": "$versions"
}, {
"$match": {
"versions.branch": branch
}
}, {
"$unwind": "$versions.labels"
}, {
"$group": {
"_id": {
"$toUpper": "$_id"
},
"id": {
"$addToSet": "$product_name"
},
"max": {
"$max": "$versions.name"
},
"author": {
"$addToSet": "$versions.author"
},
"labels": {
"$addToSet": "$versions.labels"
},
"branch": {
"$addToSet": "$versions.branch"
},
"level": {
"$addToSet": "$level"
},
"vob": {
"$addToSet": "$vob"
},
"Name": {
"$addToSet": "$_id"
},
"is_product": {
"$addToSet": "$is_product"
},
"prefix": {
"$addToSet": "$prefix"
},
"decclass": {
"$addToSet": "$doctype"
},
"product_number": {
"$addToSet": "$versions.product_number"
},
"status": {
"$addToSet": "$versions.status"
},
"revision": {
"$addToSet": "$versions.revision"
},
"variant": {
"$addToSet": "$versions.variant"
}
}
}, ])
web应用程序很慢,想加快速度,你能建议我做什么,创建哪些索引,查询顺序好吗?或任何其他建议。我创建了索引
db.element.ensureIndex({product_name: 1, doctype: 1, prefix: 1})
我应该使用复合索引还是其他?当我尝试创建索引时
db.element.ensureIndex({versions.branch: 1, doctype: 1, prefix: 1})
Thu Jun 20 09:45:54.983 JavaScript execution failed: SyntaxError: Unexpected token .