【发布时间】:2021-03-07 17:35:52
【问题描述】:
我正试图找出这段代码失败的原因:
db.restaurants.drop();
db.restaurants.insertMany( [
{ "_id" : 1, "borough" : "Manhattan"},
] );
db.restaurants.createIndex({
"borough": "text"
})
db.restaurants.aggregate([
{ $match: { $text: { $search: "a" } } },
{ $sort: {score: {"$meta": "textScore"}}},
{ $project: {"_id": true}},
])
错误输出:
uncaught exception: Error: command failed: {
"ok" : 0,
"errmsg" : "FieldPath field names may not start with '$'.",
"code" : 16410,
"codeName" : "Location16410"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:18:14
_assertCommandWorked@src/mongo/shell/assert.js:639:17
assert.commandWorked@src/mongo/shell/assert.js:729:16
DB.prototype._runAggregate@src/mongo/shell/db.js:266:5
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1058:12
@(shell):1:1
我知道这与项目声明有关...
提前谢谢你!
-丹尼尔
【问题讨论】:
-
将失败的代码减少到一个阶段。
标签: mongodb aggregation-framework