我正在使用 MongoDB 中的内置示例数据库(餐厅)。
我正在尝试运行下面的查询,但出现以下错误。
查询
db.restaurants.find(
{"grades.1.grade": "A"},
{行政区:1,美食:1,成绩:{$slice: [0,2]},"grades.score":1}
)
检索文件失败
[sample_restaurants.restaurants@atlas-1x6mis-shard-0 [副本集:atlas-1x6mis-shard-0]] 数据库错误!
堆栈跟踪:
|_/ java.lang.Exception: [sample_restaurants.restaurants@atlas-1x6mis-shard-0 [副本集: atlas-1x6mis-shard-0]] 数据库错误!
|____/ Mongo 服务器错误 (MongoQueryException):在服务器 ac-wc6qid1-shard-00-02 上查询失败,错误代码为 31249,名称为“Location31249”,错误消息为“grades.score 剩余部分分数处的路径冲突”。 u51wdlv.mongodb.net:27017
包含以下值的表格。
{行政区:1,美食:1,成绩:{$slice: [0,2]},"grades.score":1}
在投影中:
grades: {$slice: [0,2]}
请求“grades”字段包含原始 grades
数组中的前 3 个文档以及所有原始字段。
"grades.score": 1
请求“grades”字段包含一个对象数组,每个对象仅包含原始数组元素的 all中的
score
字段。
查询执行器意识到它不能同时执行这两项操作,因此它会因路径冲突而提前失败。