python - How to efficiently include results of a MongoDB's cursor in another query? -


suppose have mongodb collection , i'm running 2 queries on it, , b. both returning lists of indexes documents in collection. records in intersection of a's , b's outcome, i.e. intersection of sets.

a naive implementation on pymongo this:

cursor_result_a = db.collection.find(a) result_a = [x x in cursor_result_a] cursor_result_b = db.collection.find({"$and":[{"_id":{"$in":result_a}}, b]}) 

however, approach makes me first pull outcome of first query database python , send in first query. inefficient.

how can more efficiently?


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -