MongoError:如何修复:管道需要文本分数元数据,但是没有可用的文本分数?

问题描述 投票:0回答:1

我在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
> 
javascript mongodb search-engine
1个回答
0
投票

看来目前mongodb不允许在$text阶段使用$lookup,虽然我认为理论上它至少可以是版本3.6.94.0.9

看起来他们可能支持这个版本4.1.84.1.9,但我无法测试它。

也可以看看:

© www.soinside.com 2019 - 2024. All rights reserved.