Can you determine what filter condition did not match?

Hi all,

Is it possible to determine which filter field did not match any documents? For example, for a simple get query like the one below, can I find out which of the two fields are not a match?

docs = collection.find({"_id": _id, "editors": "someguy"})

In this case, I would like to know if it’s the _id field or the editors field that did not match the document found. When I run docs.explain() I can see that it examines one document as the _id field matches, but it doesn’t specify that the editors field did not match.

I can easily do this in two calls, but I would like to keep the number of calls to a minimum.

The only way I can see is you find with _id only and test your other condition in your code.

If _id matches you get a document to test the second condition otherwise you know _id does not match.

If you want to know if some other _id has editors:someguy, that is another story.

Thanks. I think this is the best way.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.