在pymongo中输出的漂亮打印

Kou*_*hik 5 mongodb pymongo python-3.x

我正在使用pymongo驱动程序使用Python与Mongodb一起工作.每当我在python shell中运行查询时,它都会返回一些非常难以理解的输出.我使用了.pretty()mongo shell 的选项,它以结构化的方式提供输出.

我想知道是否有其他任何方法一样pretty()pymongo,它可以在一个结构化的方式返回输出?

sty*_*ane 6

我想知道pretty()PyMongo中是否有任何方法

没有 PyMongo不提供这样的方法.它仅在shell中可用.您需要使用模块中的pprint功能pprint.


Aru*_*ath 0

没有直接的方法可以以结构化方式打印 pymongo 的输出。

因为 pymongo 的输出是dict

print(json.dumps('variable with out of pymongo query')) 
Run Code Online (Sandbox Code Playgroud)

我认为这将达到你的目的