Is it posible getting mongo _id after inserting data from php?

3,748 views
Skip to first unread message

Nuris Kandar Musthafa

unread,
Nov 19, 2010, 5:30:55 AM11/19/10
to mongod...@googlegroups.com
According to what I know about mongoDB, every we insert data into mongoDB collections, mongoDB will automatically generate objectID or in collection the record will be '_id'

if I have script like below:
<?php

$doc = array('a'=>1, 'b'=>2);
$m 
= new Mongo();
$collection $m->foo->bar;
$collection->insert$doc );

?>

is it possible to get last '_id' from the data I have inserted into mongoDB?
if it's possible how, how about the script?

thanks.
regards,


Nuris.


Kyle Banker

unread,
Nov 19, 2010, 7:42:43 AM11/19/10
to mongod...@googlegroups.com
The 'insert' method should return the object id. These ids are
generally created client-side.

> --
> 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.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>

Kristina Chodorow

unread,
Nov 19, 2010, 10:19:53 AM11/19/10
to mongod...@googlegroups.com
$doc will contain an _id field after the insert.

Nuris Kandar Musthafa

unread,
Nov 21, 2010, 10:46:57 PM11/21/10
to mongod...@googlegroups.com
thanks Kristina, it works fine...
Reply all
Reply to author
Forward
0 new messages