0

I need to find a way to filter results from a MongoDB database, based on fields found in the current table, and a field found in another table which is linked to the current table. Tables format:

{
   "_id": ObjectId("51af256a0da4dd7804000007"),
   "enddate": ISODate("2013-06-14T21:00:00.0Z"),
   "main": false,
   "name": "name 1",
   "photo": "image-1.jpg",
   "site": {
     "$ref": "Sites",
     "$id": ObjectId("51ac538c5f06751414bd9f98"),
     "$db": "local"
  },
   "startdate": ISODate("2013-04-30T21:00:00.0Z")
}   

{
   "_id": ObjectId("51d3d5b9caa8213b12e92c5e"),
   "sitefeatured": false,
   "sitename": "a",
   "sitephoto": "aa.jpg",
   "siteurl": "aaaa.com/"
}   

what i`m trying to do in ->where clause is to search in the string formed by this.name and this.site.sitename: my problem is that i don't know / didn't find how to reference to property sitename of the site object

$entries = $dm
                        ->getRepository($sTable)
                        ->createQueryBuilder('o')
                            ->where('function() { return ( (this.name + this.site.sitename).toLowerCase().indexOf("'.$_GET['sSearch'].'".toLowerCase()) !== -1 ) ? true : false }')
                            ->sort($aColumns[$_GET['iSortCol_0']], $_GET['sSortDir_0'])
                            ->limit($_GET['iDisplayLength'])
                            ->skip($_GET['iDisplayStart'])
                            ->getQuery()
                            ->execute();

Is there anything like SQL join that i didn't came across, or what's the solution?

Andrei Stanca
  • 908
  • 2
  • 11
  • 26
  • `table` ? You surely mean document. Vocabulary matters. – Florian Klein Jul 03 '13 at 11:26
  • 1
    It matters, because, contrary to Relational databases, you **can't** join collections together for the moment (in mongodb). So you're stuck with the path you took. You should read http://stackoverflow.com/questions/5681851/mongodb-combine-data-from-multiple-collections-in-to-one-how – Florian Klein Jul 03 '13 at 11:29
  • http://docs.mongodb.org/manual/core/map-reduce/#MapReduce-Outputoptions – Florian Klein Jul 03 '13 at 11:30

0 Answers0