I have this record in DB
{
"_id": ObjectId("5759ccbcc2b503980c000143"),
"phone": "516-425-5878",
"orders": [
"1338475681",
"1891805481",
"1891805481"
]
}
Here is my code.
$collection = $mongo_db_obj->selectCollection('scrapers', 'leads');
$data = array(
'phone' => '516-425-5878',
"orders" => array('$in'=>1891805481)
);
$doc = $collection->findOne($data);
dump($doc);
I want to check if particular phone
and and order id inside orders
array exists or not. But my code is giving error.
I have tried this one too.
$data = array(
'phone' => '516-425-5878',
"orders" => array(1891805481)
);
But it returns empty results.
How do I check that?
$in operator selects documents where field values matches values in an array.
Please try executing following code snippet as a solution to above mentioned issue
$conn = new MongoClient('localhost:27017');
$db = $conn->selectDB("mydb");
$collection=$db->mycoll;
$data = array(
'phone' => '516-425-5878',
"orders" => array('$in'=>array('1891805481'))
);
$data=$collection->findOne($data);