MongoDB - Can't canonicalize query: BadValue unknown operator: $meta

mongodb

Solution

Turns out I just had the brackets in the wrong place.. and it should have read.

//This works
db.test.find(
    { $text: { $search: 'york' } },
    { score: { $meta: 'textScore' } }
);

Problem

This happened to me in 2.6.1 - So, in case anyone wanders into this error, I thought I'd write the answer out. This first command worked fine, but the second one didn't. ``` db.test.find({$text: {$search: 'york'}} ) db.test.find({$text: {$search: 'york'}, score: {$meta: 'textScore'}} ) ``` and threw up the error below ``` {"$err": "Can't canonicalize query: BadValue unknown operator: $meta", "code": 17287} ```

Original source