coen-hyde / Shanty-Mongo

Shanty Mongo is a mongodb library for the Zend Framework. Its intention is to make working with mongodb documents as natural and as simple as possible. In particular allowing embedded documents to also have custom document classes.
Other
200 stars 52 forks source link

Array Element by Position ? #49

Closed zapatista closed 12 years ago

zapatista commented 12 years ago

i've a data : "relatedItem" : { "0" : { "itemGuid" : "10" }, {"1" : {"itemGuid" : "20" }

I tried:

how to match an entire document within the relatedItem array ?

thanks, I appreciate the quick response

coen-hyde commented 12 years ago

Hi Zapatista,

Hmm, it might pay to read the documentation a bit more. First you're running find on documents where you should be running find on collections.

eg. Catalog_Class_Name::find(array('relatedItem.$.itemGuid' => 20));

That should return the document with a subdocument containing itemGuid value of 20. Remember you're querying from php, not js so we can't use native json. Queries are structured using php arrays so you do use '=>' to separate values. Apart from that the query language is exactly the same as standard mongo.

Cheers, Coen

zapatista commented 12 years ago

i've tried that before Catalog_Class_Name::find(array('relatedItem.$.itemGuid' => 20)); no result; class Application_Model_Db_Table_Mongo_Catalog extends Shanty_Mongo_Document { protected static $_db = "holemp"; protected static $_collection = "catalog"; protected static $_documentSetClass = "Application_Modul_Db_Table_Mongo_Catalogs"; protected static $_requirements = array( 'relatedItem' => 'DocumentSet', 'relatedItem.$.itemGuid' => 'Required', ); } class Application_Modul_Db_Table_Mongo_Catalogs extends Shanty_Mongo_DocumentSet {}

thanks,