how to return partial array match in inner array of mongodb? -


i showing example of mongodb collection document structure. have shown expected result while making query have shown.

document structure::

{    _id : "132423423",    name : "hi_code",    my_entries : [          {            e_id : "12345",            e_name : "f1",            e_posted : "2010-05-01",          },          {            e_id : "12346",            e_name : "f2",            e_posted : "2010-06-01",          },          {            e_id : "12346",            e_name : "f3",            e_posted : "2010-03-02",          }     ]  }  

query structure::

db.mycollection.find( { my_entries : { $elemmatch : { e_posted : "2010-06-01",  e_name : "f2" } } } )  

expected result::

{    _id : "132423423",    name : "hi_code",    my_entries : [          {            e_id : "12346",            e_name : "f2",            e_posted : "2010-06-01",          }    ]  }  

i don't want use map reduce because working on big database make slow performance, want make possible find query.

your actual result entire document matches query.

you expecting part of document returned, there no way specify matching array elements returned in 2.0.

starting version 2.2 (next production version available unstable development version 2.1) able use aggregation framework want in example.

2.2 supports $elemmatch projection operator - note return @ one matching array element.

with aggregation framework can this:

db.mycollection.aggregate( [      {$match : { my_entries : { $elemmatch : { e_posted : "2010-06-01", e_name : "f2" } } } },      {$unwind : "$my_entries"},      {$match : { my_entries : { e_posted : "2010-06-01", e_name : "f2" } } } ] ) 

this return many documents there matching entries in my_entries arrays. if want group them need add {$group:} entry @ end of pipeline.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -