[SERVER-62579] Community Edition 5.0.5 "text index required for $text query" with index present Created: 12/Jan/22  Updated: 02/Feb/22

Status: Needs Scheduling
Project: Core Server
Component/s: Text Search
Affects Version/s: 5.0.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Dylan Knight Assignee: Backlog - Compass Team
Resolution: Unresolved Votes: 0
Labels: text_index
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

2019 Macbook Pro (Intel i9), Mac OS Monterey 12.1. Mongo compiled from tarball via Macports (macports.org).


Operating System: ALL
Steps To Reproduce:
  1. Install Community Edition on MacOS
  2. Create text index on collection
  3. Run a text search query
Participants:

 Description   

It seems as though my text index isn't being found when a $text query is issued to a single node cluster running locally on my macbook, currently version 5.0.5. I have another deployment of our system running against Atlas and don't experience any problems querying against that db's text index on the same collection. The indices in question on both deployments were originally created with the MongoDB Compass UI.

I ran the commands below in MongoSH in MongoDB Compass but got a similar result from the Node.js driver through mongoose.

> db.accountmembers.getIndices()
[
  { v: 2, key: { _id: 1 }, name: '_id_' },
  {
    v: 2,
    key: { _fts: 'text', _ftsx: 1 },
    name: 'textSearch',
    background: false,
    weights: { email: 1, firstname: 1, lastname: 1 },
    default_language: 'english',
    language_override: 'language',
    textIndexVersion: 3
  }
]
 
> db.accountmembers.find({$text: {$search: "gmail", $language: "english"}})
MongoServerError: text index required for $text query

I tried deleting and recreating the index as well. It did't help.

I googled around for possible reasons this might be happening, but found nothing relevant.



 Comments   
Comment by Dylan Knight [ 02/Feb/22 ]

I don't think this is a Compass issue

Comment by Dylan Knight [ 25/Jan/22 ]

it's a single-member replica set

Comment by Dylan Knight [ 25/Jan/22 ]

I was able to get the same behavior in the Terminal with the old "mongo" command line tool. `createIndex` hung. I killed the process, logged back in, it listed the index, but I got the missing index error when I ran the query.

The macports `mongo-tools` package doesn't seem to have 'mongosh' in it yet. @dmitry.agranat@mongodb.com 

Comment by Dmitry Agranat [ 25/Jan/22 ]

I was running on a replica set. This might not be related to the Server-side so I am moving this to the Compass team to take a look.

Just to confirm, is it a single-member replica set or a PSA deployment?

Comment by Dylan Knight [ 25/Jan/22 ]

I ran the commads in the bottom shell view of Compass 1.29.4

Are you running a single node replica set, too?

Comment by Dmitry Agranat [ 25/Jan/22 ]

I am unable to reproduce this on MongoDB 5.0.5 communitry or enterprise but I am also not having troubles with the shell just spinning and not returning to a prompt:

> db.accountmembers.createIndex({email: "text", firstname: "text", lastname: "text"}, {name: "textSearch"})
{
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"createdCollectionAutomatically" : true,
	"commitQuorum" : "votingMembers",
	"ok" : 1,
	"$clusterTime" : {
		"clusterTime" : Timestamp(1643119723, 2),
		"signature" : {
			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
			"keyId" : NumberLong(0)
		}
	},
	"operationTime" : Timestamp(1643119723, 2)
}
> db.accountmembers.getIndexes()
[
	{
		"v" : 2,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_"
	},
	{
		"v" : 2,
		"key" : {
			"_fts" : "text",
			"_ftsx" : 1
		},
		"name" : "textSearch",
		"weights" : {
			"email" : 1,
			"firstname" : 1,
			"lastname" : 1
		},
		"default_language" : "english",
		"language_override" : "language",
		"textIndexVersion" : 3
	}
]

So the error you were getting is expected as in "the index you are trying to retrieve does not exist because it was not created". I am going to try to understand why you have the mentioned shell issues. What shell/mongoSH version do you use?

Comment by Dylan Knight [ 25/Jan/22 ]

@dmitry.agranat@mongodb.com, I dropped the index and then ran the above command again in the shell, copied here for pedantic completeness, but the shell is now just spinning and hasn't returned to a prompt. I've let it sit for a good few minutes.

db.accountmembers.createIndex({email: "text", firstname: "text", lastname: "text"}, {name: "textSearch"})

After killing the shell process, and reconnecting. I can run the remaining commands and I get the same output as I pasted above:

> db.accountmembers.getIndices()
< [
  { v: 2, key: { _id: 1 }, name: '_id_' },
  {
    v: 2,
    key: { _fts: 'text', _ftsx: 1 },
    name: 'textSearch',
    weights: { email: 1, firstname: 1, lastname: 1 },
    default_language: 'english',
    language_override: 'language',
    textIndexVersion: 3
  }
]
> db.accountmembers.find({$text: {$search: "gmail", $language: "english"}})
MongoServerError: text index required for $text query

Does this sufficiently prove that I'm not wasting your time?

Comment by Dmitry Agranat [ 25/Jan/22 ]

Thanks dylan.knight@securedcommunications.com, can you post here the exact method used to create text index via MongoSH together with the corresponding db.collection.getIndexes() command?

Comment by Dylan Knight [ 25/Jan/22 ]

I'm pretty sure I created it with the Compass UI, @dmitry.agranat@mongodb.com. But I might have also have used the mongo shell, e.g.:

db.accountmembers.createIndex({email: "text", firstname: "text", lastname: "text"})

Comment by Dmitry Agranat [ 25/Jan/22 ]

Hi dylan.knight@securedcommunications.com, could you please post here how that index was created, was it just text: true into the name field in the schema or with:

schema.index({username: 'text'})

Generated at Thu Feb 08 05:55:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.