Skip to content
Advertisement

How can I limit output of MongoDB query in Python?

I have this example MongoDB entry in a users DB:

JavaScript

And I’m using Pymongo to query the file named “test”:

users.find_one({'files.filename':"test"})

How can I limit the output from Pymongo, so it only gives me the dict where “test” is contained? In other words, I want it to output this:

JavaScript

Advertisement

Answer

Here’s one way you could do it.

JavaScript

Try it on mongoplayground.net.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement