On a relational DB you'll do that with a Join, however in mongodb you can either:
de-normalize your referenced category in your Wallpaper document:
/**
* @MongoDB\EmbedMany(targetDocument="Category")
*/
private $categories;
(notice the EmbedMany)
In this way your query will work (but the categories will be duplicated inside each Wallpaper)
Or do this simple trick (if the number of categories isn't too high):
//Get all the ids of the published categories:
$categories = $this->createQueryBuilder('ApplicationDefaultBundle:Category')
->field('published')->equals(true)
->getQuery()
->execute()
$categoriesIds = array();
foreach($categories as $c) {
$categoriesIds[] = $c->getId();
}
//Get the wallpapers for that categories:
$wallpapers = $this->createQueryBuilder('ApplicationDefaultBundle:Wallpaper')
->field('categories.$id')->in($categories)
->getQuery()
->execute()
If the published categories are only 100-200 this trick is ok.