PHP - findOne by _id

143 views
Skip to first unread message

NTulip

unread,
Feb 25, 2010, 11:12:00 PM2/25/10
to mongodb-user
Hi

Using the PHP driver, I am trying to access a document by it's _id and
I can't get a result back. I am passing to it an array as such:

$mid = new MongoId("4b80c94a8ead0eaf12040000");
$col->findOne(array('_id' =>$mid));

It works fine if I query against any other field that is not a
MongoId.

Could anyone help please?

Thank you

Fitz Agard

unread,
Feb 25, 2010, 11:38:39 PM2/25/10
to mongod...@googlegroups.com
I've used the same code to get results from Mongo with the '_id'. What you have there looks right.

I'm a fan of doing var_dump on all the output if you're not getting back what you expected. Check that the $mid is actually returning object(MongoId) and $output = $col->findOne(array('_id' => $mid)) is returning an array.

Hope that helps.

-Fitz

Kristina Chodorow

unread,
Feb 26, 2010, 8:57:09 AM2/26/10
to mongod...@googlegroups.com
Maybe you saved the _id as a different type? If you post a var_dump
of the document you're trying to get and the string version of its _id
field we can probably help more.

> --
> 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.
>
>

Reply all
Reply to author
Forward
0 new messages