php - How to check if record exists by searching into inner array -
i have record in db
{ "_id": objectid("5759ccbcc2b503980c000143"), "phone": "516-425-5878", "orders": [ "1338475681", "1891805481", "1891805481" ] }
here 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 check if particular phone
, and order id inside orders
array exists or not. code giving error.
i have tried 1 too.
$data = array( 'phone' => '516-425-5878', "orders" => array(1891805481) );
but returns empty results.
how check that?
$in operator selects documents field values matches values in array.
please try executing following code snippet solution 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);
Comments
Post a Comment