PHP with MongoDB – Match in_array with ObjectId

  mongodb, php

I have 2 queries from a MongoDB Atlas DB. I am now trying to process them in my PHP page:

  1. Returns a single $player item with only an _id field projected
  2. Returns an array of $admins items with only the _id field projected

If I print_r() both variables, I get this output:

MongoDBModelBSONDocument Object ( [storage:ArrayObject:private] => Array ( [_id] => MongoDBBSONObjectId Object ( [oid] => 609d0993906429612483cea0 ) ) ) 
MongoDBModelBSONArray Object ( [storage:ArrayObject:private] => Array ( [0] => MongoDBBSONObjectId Object ( [oid] => 609d0993906429612483ceb0 ) [1] => MongoDBBSONObjectId Object ( [oid] => 609d0993906429612483cea0 ) ) ) 

How can I perform a search / match that the former is contained within the latter?

I have tried with a PHP in_array() but it errors that the 2nd variable isn’t of type array.


Or should I convert the _id fields into string values as the query is executing?

Source: Ask PHP