Pretty printed items in pimongo

I am using the pymongo driver to work with Mongodb using Python. Every time I run a request in a python shell, it returns me some output that is very hard to understand. I used the .pretty() parameter with the mongo shell, which gives the result in a structured way.

I want to know if there is any method like pretty() in pymongo that can return the output in a structured way?

+5
source share
4 answers

I want to know if there is any method like pretty() in PyMongo

No PyMongo provides such a method. It is available only in the shell. You need to use the pprint function from pprint .

+4
source

There is no direct method for listing pymongo in a structured way.

since from pymongo is a dict

print (json.dumps ('variable without pymongo request))

it will serve your purpose, I think

0
source

In fact, you can also program it yourself, for example:

 db = connection.[dbname] collection = db.[yourcollectionname] for col in collection.find({}): for keys in col.keys(): print ('{', keys, ":" , col[keys] , '}' ) 

I think it will be useful or take it as an option.

0
source

It probably depends on your development environment, not on the pignongo itself. pymongo is responsible for data manipulation and communication with mongodb. I use Visual Studio with PTVS, and I have options that are provided in Visual Studio. PyCharm is also a good option for an IDE that allows you to view your code and JSON variables in a formatted structure.

-1
source

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


All Articles