Hello community. I am a very experienced PHP/MySql developer but I am struggling mightily querying an existing MongoDB collection.
When I query in console, I get the expected result
db.somecollection.find({
_id: {
$in: [
ObjectId("580962ca1a0000900a59cf28")
]
}
})
When I query in PHP, I get an error:
$client = new MongoDB\Client(mongodb://localhost);
$db = $client->somedb
$db->somecollection->find(
[
"_id" => [
"$in" => [
ObjectId("580962ca1a0000900a59cf28")
]
]
]
);
Notice : Undefined variable: in...
Fatal error : Uncaught Error: Call to undefined function ObjectId() in...
My collection looks like this:
{
"_id" : ObjectId("1234567890abcdefghijklmn"),
"someobject" : {
"_id" : ObjectId("2345678901abcdefghijklmn"),
"someotherobject" : ObjectId("3456789012abcdefghijklmn"),
"somebiggerobject" : {
"_id" : ObjectId("4567890123abcdefghijklmn"),
"object1" : "abided",
"object2" : {
"_id"
.
.
.
},
{
"_id" : ObjectId("1234567890nmlkjihgfedcba"),
"someobject" : {
"_id" : ObjectId("2345678901nmlkjihgfedcba"),
"someotherobject" : ObjectId("3456789012nmlkjihgfedcba"),
"somebiggerobject" : {
"_id" : ObjectId("4567890123nmlkjihgfedcba"),
"object1" : "abided",
"object2" : {
"_id"
.
.
.
First, I want to know how to query by ObjectId.
Next, and more importantly, I need to be able to do a more advanced query where I:
Return all documents containing someobject.somebiggerobject.object2._id = ObjectId(“skdjhfskjdfsdjfh”)
Make sense?
Oh, and I am on a deadline