Re: [mongodb-user] Getting ObjectID in Mongo

60 views
Skip to first unread message

Sam Millman

unread,
Sep 28, 2012, 8:26:01 AM9/28/12
to mongod...@googlegroups.com
It depends on the server-side language you are using? Which language are you intending on programming in?

On 28 September 2012 07:43, Miguel Blauwbloeme <mblauw...@gmail.com> wrote:
Hi all,

I new to mongo and I am searchin on how to get the ObjectID of a document when I do a query on a certain field in that document ?
Can someone help me with this ?

Thanks
Miguël

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

Kay

unread,
Sep 28, 2012, 4:00:48 PM9/28/12
to mongod...@googlegroups.com
Hi Miguel -- 
when you query on a particular field in that document, is the _id field being returned?  The _id field should contain the ObjectID of the document.

If you don't see the _id field as part of the resulting document, could you specify the query that you are running?  


Regards,

Kay

Miguel Blauwbloeme

unread,
Oct 2, 2012, 4:16:16 AM10/2/12
to mongod...@googlegroups.com
Forgot to mention
I am using django.


Miguël

Op vrijdag 28 september 2012 08:43:53 UTC+2 schreef Miguel Blauwbloeme het volgende:

Kay

unread,
Oct 10, 2012, 1:48:43 PM10/10/12
to mongod...@googlegroups.com, mblauw...@gmail.com
Hi Miguël --

Sorry for the delay but was this what you were trying to do -- access the _id field which contains the ObjectID?

>>> myRecords = myCollection.find( { }, { '_id': 1 } )
>>> for record in myRecords:
record['_id']

Regards,

Kay 

On Friday, September 28, 2012 2:43:53 AM UTC-4, Miguel Blauwbloeme wrote:
Reply all
Reply to author
Forward
0 new messages