I'm trying to query MongoDB from Python, I'm just getting into these technologies.
I have this code
import pymongo
from pymongo import MongoClient
client = MongoClient()
db = client.crawler.users
res = db.find()
print( res )
It throws me this message:
<pymongo.cursor.Cursor object at 0x7f438d574cd0>
Process exited with code: 0
I expected a response like this since from the Mongo console if you run it:
> db.users.find()
{ "_id" : ObjectId("5b3fd50706dd45b669417454"), "NAME" : "FOO", "LAST_NAME" : "BAR" }
{ "_id" : ObjectId("5b3fdd2e613d0b159da70742"), "NAME" : "POO", "LAST_NAME" : "MAR" }
I appreciate your patience
What happens is that you are printing the cursor. According to the documentation, the method
find
returns an instance ofpymongo.cursor.Cursor
. To be able to print the documents you have to iterate the cursor:With that you should see the content of each document in the collection. It looks better if you use
pprint
: