PHP MongoDB Nested Document Search -


i have nested document have language dependent content , want search if content have data specific language , query should return me content else false.

i tried query option

$data = $collection->findone(array('original'=>'what this', 'translation.language'=>'english') ); 

i expecting result:

{        "language": "english",        "quote": "what this" } 

but above query return both language content. can please share code regarding saving , updating data using php

my collection:

{    "_id": objectid("56a8844bc56760810e483815"),    "language": "english",    "original_key": "what this",    "translation": [      {        "language": "english",        "quote": "what this"     },      {        "language": "spanish",        "quote": "what spanish"     }   ] }    

use positional $ operator in projection document of findone() method when need 1 particular array element in selected documents:

// search criteria nested array $query = array(     'original' => 'what this',      'translation.language' => 'english' );  // projection (fields include) $projection =  array('_id' => false, 'translation.$' => true);  $result = $collection->findone($query, $projection); $data = $result->translation; var_dump($data); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -