MongoError: What to do when the pipeline needs text score metadata, but no text score is provided?

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
> 

Answer №1

At the moment, it seems that mongodb is not permitting the usage of $text within the pipeline of a $lookup stage. However, in theory, this could be feasible as of versions 3.6.9 and 4.0.9, at least.

There are indications that they might introduce support for this feature in version 4.1.8 or 4.1.9, but verification testing has not been conducted yet.

Also worth checking out:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Trouble with fetching data in Backbone

I'm facing an issue where the Backbone/Marionette Controller and Collection are not fetching properly. define(["jquery", "backbone","models/Poi"], function($, Backbone, Poi) { // Creating a new instance of Backbone Poi class object ...

The argument type of '() => JQuery' cannot be assigned to a parameter type of '() => boolean'

Having trouble writing a jasmine test case for my method due to an error: spec.ts(163,18): error TS2345: Argument of type '() => JQuery' is not assignable to parameter of type '() => boolean' Any suggestions on how to resolve ...

Encountering unexpected fetch requests to JSON files when using getStaticProps/getStaticPaths

My webpage seems to be functioning correctly, however I have noticed that in the console there are 5, 404 errors appearing on fetch requests. It's puzzling where these errors are originating from. Interestingly, these 404 errors only occur in the pro ...

Condense a lineup of names into only two rows

I have a challenge where I need to showcase a list of names separated by commas, pulled from an array in my React component. The HTML output should appear as follows: <div> <span>Liza</span>, <span>Eric</span>, <span>Mic ...

JQuery enables nested sorting functionality

I need to enable the sortable feature specifically for the charts. Index.cshmtml <div id="sortable" class="col-lg-9"> <div class="col-lg-12 col-md-12 padding hidden" id=@($"chartNumber{Model.Charts[ ...

Disable postback onkeypress event in the page

I am encountering an issue with my ASP.NET 4.0 form where I have multiple textboxes within divs that are dynamically shown or hidden. Specifically, I have a textbox with an onkeypress event defined as follows: <fieldset> <div class="WizardSte ...

Is React Authentication with Ruby Gem Devise possible in JavaScript?

Recently, I started working on a rails app and decided to switch the front end to React gradually. Currently, my focus is on converting the menu bar with dynamic links based on whether the user is logged in or not. Below is the original code snippet from t ...

Unable to retrieve data by Id in NodeJS

Just dipping my toes into the world of NodeJs, I watched a couple of tutorials but when I tried to code on my own, I hit a roadblock. My current challenge involves editing a post stored in my Mlab (Mongo) database. Despite receiving a positive response, I ...

Simple method for implementing a fade effect on a React component with raw JavaScript techniques?

I am seeking a way to have my React component smoothly fade in upon being mounted. The component's outermost DIV starts with inline style display:none. Within the componentDidMount() method, I've written the following code: let el = document.que ...

Guide to including spinner in React JS with TypeScript

I need help with adding a spinner to a React component. The issue I'm facing is that the spinner does not disappear after fetching data from an API. Can someone please point out what I am doing wrong? Here is the code snippet: import React, { useSta ...

Error in react-native while attempting to find the lowest common ancestor of `responderInst` and `targetInst` using `Event

After upgrading my react-native app to version 0.44, I encountered an issue where the app would start up without any problems in both the simulator and on a mobile device. However, when I tried pressing a component like a button or widget, a red error scre ...

Issue with the positioning of bootstrap popover after content is added

Having trouble writing a function that adds a textarea to the bottom of a popover content when clicking on a button. The issue is that once the textarea is displayed, the popover extends downward and obscures the text. I'm looking for a solution where ...

What is the most effective method for saving color hex codes in a mongodb/mongoose database?

For storing hexadecimal colors like #fff, #fafafa, and red for my items, which data type would be most suitable? I appreciate your help! ...

Install the npm package if there have been modifications to the package.json file

In short: Can we make npm install run automatically before executing any npm script if the package.json file has been modified? Situation Summary Imagine you switch to a branch that has updated the package.json file. You try running npm run my-script, bu ...

Transform the values of an array within a JSON object into a single string by looping through them

Here is a JSON object that I need to transform: // TableData { "0": { "damage_type": "Scratch", "regions": [ "front side", "back side" ], ...

Mastering the art of navigating through multiple nested objects is achievable by harnessing the power of recursive

I'm utilizing the AngularTree directive in my Angular application to display a tree view of a specific data structure. The data structure can be viewed at https://jsfiddle.net/eugene_goldberg/Lvwxx629/17/. You can find more information about the Angul ...

Retrieve an array from the success function of a jQuery AJAX call

After successfully reading an rss file using the jQuery ajax function, I created the array function mycarousel_itemList in which I stored items by pushing them. However, when I tried to use this array in another function that I had created, I encountered t ...

Designing a login system with MEAN stack architecture?

I am currently in the process of building a web application using the MEAN stack (MongoDB, Express, AngularJS, and node.js). Specifically, I am working on implementing a login system and securing certain routes in my Angular app so that they are only acces ...

Ways to substitute EACH word in JQuery or JavaScript?

I've been attempting to substitute each word in a passage with another, but I haven't come across any method of achieving this. Here's an example: from this> Hello, my name is Robert. to this> Greetings Greetings Greetings Greetings ...

Clicking on a card will cause it to expand

Exploring Material-UI-React for the first time to create expanding cards, I've encountered an issue where all cards expand when one is clicked. How can I modify my code so that only the clicked card expands without affecting the others? const useSt ...