2

I am trying to find by id a document in the database, but I get None. What am I doing wrong?

python:

card = mongo.db['grl'].find_one({'id': 448510476})

or:

card = mongo.db['grl'].find_one({'id': '448510476'})

document:

{"_id":{"$oid":"5f25b1d787fc4c34a7d9aabe"},
"id":{"$numberInt":"448510476"},"first_name":"Arc","last_name":"Fl"}

enter image description here

1
  • do you able to get the output if you use any other field? Commented Aug 1, 2020 at 20:52

1 Answer 1

2

I'm not sure how you are initializing your database but try this:

from pymongo import MongoClient

client = MongoClient("mongodb://127.0.0.1:27017")
db = client.database #Selecting database named "database"

#find one in collection named "collection"    
card = db.collection.find_one({"id": "448510476"})

print(card)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.