K
K
Kirill Sadovnik2015-11-15 00:11:47
NoSQL
Kirill Sadovnik, 2015-11-15 00:11:47

How to sort MongoDB selection by number of conditions met in $or?

I implement in the application something like a search by filters.
To select all documents that match at least one filter, I decided to use the $or operator and list all conditional filters in it. But now how can I sort the documents by the number of conditions met, so that first there are those that satisfied all the conditions, and at the very end those that satisfied one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2015-11-15
@lega

You'd better use the text index, the most relevant documents will "pop out" at the top.
You can also try sphinx/elastic search.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question