vadimdemedes / mongorito

🍹 MongoDB ODM for Node.js apps based on Redux
1.38k stars 90 forks source link

Must have $meta projection for all $meta sort keys #163

Open ghost opened 7 years ago

ghost commented 7 years ago

I'm trying to do a full text search and sort the results by score, but when I run the query I get

Must have $meta projection for all $meta sort keys

This is what I have so far

Model
   .limit(10)
   .skip((page - 1) * 10)
   .sort({ score: { $meta: 'textScore' } })
   .find(query, { score: { $meta: 'textScore' } })
   .then(records => {
     // do something
   })

Am I doing something wrong?

ghost commented 7 years ago

Never mind, I switched to mongorito@v3 and saw the .search() API. Now the question is: what would be the best approach to count all matched records using full text search for pagination?

niallobrien commented 7 years ago

I haven't tried it, but there is a count function in the code, have you tried it?