Flame_Phoenix Flame_Phoenix - 1 year ago 117
Javascript Question

Mongodb "Can't canonicalize query" error


Find what is wrong with my MongoDB query


I have a drinks collection, where I enter data like the following:

name: "Orange Banana",
ingredients: [], //list of ingredients
preparation: "Mix everything and have fun!",
Source: "Super Smoothies, p. 142"

I am trying to create a search by name functionality, and to achieve it I have created a
index, according to the documentation:

So I used the following:

db.smoothies.createIndex({name: 'text'})

Now, when I make a simple
query like the following one, it works:

db.smoothies.find({ $text: { $search: "Orange" } })

But when i try to define case sensitivity, it fails:

db.smoothies.find( { $text: { $search: "orange", $caseSensitive: true } } )

And I get the following error:

error: {
"$err" : "Can't canonicalize query: BadValue extra fields in $text",
"code" : 17287


I have taken this example from the documentation, and I can't understand why it fails. Can someone help me figure it out?

Answer Source

you need mongodb version 3.2 at least to use this query

have a look at the 2.6 documentation for text index :


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download