How to query mongodb using a list of items

Given the fact that I have a list of URLs (stored in a variable urls), is it possible to make a mongodb request to get all the documents in the collection that have a key (say url) that matches one of them in urls?

Currently, I can do this by doing N collection requests (with N = len (urls)), but I'm sure I don't have the mongodb function that allows me to do things faster.

I have to clarify that I have this list of urls thanks to the mongodb request.

Here is my code (in python), two collections: viewsand resources:

urls = []                                              
for url in db.views.find().distinct("url"):
    urls.append(db.resources.one({'url': url}))

Is there a way to make these N queries just one?

EDIT: The final source code, to do something like this, uses the $ in operator, for example:

urls = db.views.find().distinct("url")
list(db.resources.find({'url': {'$in': urls }}))
+3
1
+5

All Articles