0 votes
1 view
in Web Technology by (37.4k points)

I have a partner collection and I am using pymongo to retrieve the data

When I query the collection with MongoDB, I see the following result

db.partner.find({'unique_key': 'c89dbe313932008febde61cdd2a071a1d'},{})

{ "_id" : ObjectId("4eb463cb158acb554e8c9c11"), "unique_key" : "c89dbe313932008febde61cdd2a071a1d", "name" : "ABC", "primary_key" : 12 }  

But when I query via pymongo, here is what I do

for document in collection.find(find, criteria):

    print document  

where find = {'unique_key': 'c89dbe313932008febde61cdd2a071a1d'} and

      criteria = {}

Here is what I see in result:

{u'_id': ObjectId('4eb463cb158acb554e8c9c11')}  

and I don't get name and primary_key in result, am I missing something?

Thank you

1 Answer

0 votes
by (80.9k points)

In pymongo find(), you have set the criteria as an empty dictionary so it means that it will only return the _id of the particular document, not the other fields of the specified collection. Whereas in mongo find(), you have specified the filter that means the _id of the document so it will return all the fields that the particular document is having. If you want all the fields of the document then set the second parameter of the find() that is the projection parameter as empty or you can also omit this parameter. But if you want to get a specific field of the document then don’t leave that parameter empty.

Are you interested in learning MongoDB? Check out this MongoDB Certification training course.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 18, 2019 in Web Technology by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...