我直接在MongoDB 3.6.6 shell中运行以下命令,我不知道从哪里开始麻烦解决错误pipeline requires text score metadata, but there is no text score available
首先,这就是我通过Mongoose创建索引的方式。我用db.collection.getIndexes()检查过,它们似乎还可以:
ProgramItem.schema.index({ name: 'text' }, {
weights: {
name: 10
},
default_language: 'english'
})
Post.schema.index({
title: 'text',
content: 'text'
}, {
weights: {
title: 10,
content: 5
},
default_language: 'english'
})
控制台输出:
> db.posts.aggregate([
... { $limit: 1 },
... {
... $facet: {
... posts: [
... {
... $lookup: {
... from: 'posts',
... pipeline: [
... { $match: { $text: { $search: 'financial' } } },
... {
... $project: {
... title: 1,
... score: { $meta: 'textScore' }
... }
... }
... ],
... as: 'posts-results'
... }
... }
... ],
...
... programs: [
... {
... $lookup: {
... from: 'program-items',
... pipeline: [
... { $match: { $text: { $search: 'financial' } } },
... {
... $project: {
... name: 1,
... score: { $meta: 'textScore' }
... }
... }
... ],
... as: 'programs-results'
... }
... }
... ]
... }
... },
... { $project: { data: { $concatArrays: ['$posts', '$programs'] } } },
... { $unwind: '$data' },
... { $replaceRoot: { newRoot: '$data' } },
... { $sort: { score: -1 } },
... { $limit: 10 }
... ])
assert: command failed: {
"ok" : 0,
"errmsg" : "pipeline requires text score metadata, but there is no text score available",
"code" : 40218,
"codeName" : "Location40218"
} : aggregate failed
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:403:5
DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1212:12
@(shell):1:1
2018-07-16T13:10:01.930+0100 E QUERY [thread1] Error: command failed: {
"ok" : 0,
"errmsg" : "pipeline requires text score metadata, but there is no text score available",
"code" : 40218,
"codeName" : "Location40218"
} : aggregate failed :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
doassert@src/mongo/shell/assert.js:16:14
assert.commandWorked@src/mongo/shell/assert.js:403:5
DB.prototype._runAggregate@src/mongo/shell/db.js:260:9
DBCollection.prototype.aggregate@src/mongo/shell/collection.js:1212:12
@(shell):1:1
>
答案 0 :(得分:0)
目前看来mongodb不允许在$text
阶段的管道中使用$lookup
,尽管从理论上讲,从版本3.6.9
和{{ 1}},至少。
从4.0.9
或4.1.8
版本开始,他们似乎都支持此功能,但是我无法对其进行测试。
另请参阅: