Edward Newell
Edward Newell

Reputation: 18559

mongodb text search: invalid operator: $search

Closely related to this, but I'm using mongod version 3.2 which means its a different problem.

I created a text index:

> db.mycollection.createIndex({body:'text'})

Then I try to search it:

> db.mycollection.find({$text:{$search:'foo'}})
Error: error: { "$err" : "invalid operator: $search", "code" : 10068 }

It should work. (changes to the $text operator for v3.2 shouldn't affect this.) What am I doing wrong?

Upvotes: 1

Views: 585

Answers (1)

Edward Newell
Edward Newell

Reputation: 18559

The problem was caused by an old database (created by mongod 2.4) that had survived the mongodb uninstall / reinstall process. The official doumentation didn't mention it, but while uninstalling the old version, it was necessary to do:

sudo rm -r /data/db/*

(Perhaps because of how 2.4 was installed?) Deleting these files, and bringing my old data forward using the mongodump and mongorestore commands worked.

Upvotes: 0

Related Questions