MongoDB Print Pretty with PyMongo

I was looking for a printed version for MongoDB, and I understand how to do this from the shell. What I cannot find is how to do it with PyMongo, so when I run it in eclipse, the output will print quite, and not all on one line. Here is what I have right now:

  cursor = collection.find({})
  for document in cursor: print(document)

This prints everything in my collection, but every document in my collection just prints on one line. How can I change this to make it print pretty?

+4
source share
1 answer

PyMongo retrieves documents as Python data structures. So you can use pprintas follows:

from pprint import pprint

cursor = collection.find({})
for document in cursor: 
    pprint(document)
+11
source

Source: https://habr.com/ru/post/1622807/


All Articles