When I run the following command directly in MongoDB 3.6.6 shell, I encounter an error that says "pipeline requires text score metadata, but there is no text score available." I'm not sure where to begin troubleshooting this issue.
Here's how I created my indexes using Mongoose. After checking with db.collection.getIndexes(), everything seems to be in order:
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'
})
Upon running the above command in the console, I receive the following output:
> 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
>