fnaquira
fnaquira

Reputation: 342

PHP/MongoDB: finding a nested object

I am using the MongoDB driver for PHP and I need to find some nested elements. My structure looks like this:

 proce : { "type" : "cars" , "grupo" : { "_id" : "4e8478ace4b0dea06288ad63"}}

I need to get to the _id = 4e8478ace4b0dea06288ad63

I tried something like

$db->find( array( 'grupo._id' => "4e8478ace4b0dea06288ad63" ) );

but nothing happens.. thanks for your help

Upvotes: 0

Views: 953

Answers (1)

Gates VP
Gates VP

Reputation: 45287

Your basic query looks correct.

However, that grupo._id looks like an ObjectId. Your query is attempting to match a string. Is that "4e84..." number a string or an ObjectId?

You may need to use the PHP MongoId for matching.

Upvotes: 2

Related Questions