问题描述
我直接在 MongoDB 3.6.6 shell 中运行以下命令,我不知道从哪里开始排查错误 pipeline 需要文本分数元数据,但没有文本分数可用
I am running the below command directly in MongoDB 3.6.6 shell, I don't know where to start troubleshouting the error pipeline requires text score metadata, but there is no text score available
首先,这就是我通过 Mongoose 创建索引的方式.我检查了 db.collection.getIndexes(),它们似乎没问题:
First, this is how I created my indexes, through Mongoose. I checked with db.collection.getIndexes(), they seem to be OK :
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
>
推荐答案
看来目前 mongodb 不允许在 $lookup
$text> 阶段,虽然我认为理论上它可以,至少在 3.6.9
和 4.0.9
版本中.
It appears that currently mongodb does not allow the use of $text
in the pipeline of a $lookup
stage, although I think in theory it could, as of versions 3.6.9
and 4.0.9
, at least.
看起来他们在 4.1.8
或 4.1.9
版本中可能支持此功能,但我无法对其进行测试.
It does look like they might support this as of version 4.1.8
or 4.1.9
but I haven't been able to test it.
另见:
- https://jira.mongodb.org/browse/SERVER-38716
- https://github.com/mongodb/mongo/commit/21e65b332ed546077d6e54a4c5d43e02e
这篇关于MongoError:如何解决:管道需要文本分数元数据,但没有可用的文本分数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!