Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying MongoDB Subset Two Levels Deep Using PHP Driver
    primarykey
    data
    text
    <p>I've accessed the Facebook Graph API to get a JSON object representing the latest posts on my feed (my Facebook wall). I then saved it into a MongoDB collection called feeds using the PHP Mongo Driver.</p> <pre><code>//$post['feed']['data'] contains the Facebook JSON object of wall posts //create a mongo instance $mongo = new Mongo(); //access the feeds collection $feeds = $mongo-&gt;changeup-&gt;feeds; //dump the feed right into mongo $feeds-&gt;insert($post['feed']['data']); </code></pre> <p>This is what one of the arrays looks like after reading back the whole object that was placed into mongo. </p> <p>I'm only showing you one, but it gives me several more, each indexed, the next one is [1] => Array() and so on... some are structured differently, as some contain the [story] field, others contain the [message] field, and some contain both.</p> <pre><code>Query: $cursor = $feeds-&gt;find(); foreach ( $cursor as $feed ) { print_r($feed); } Result: [0] =&gt; Array ( [id] =&gt; 505212695_10150696450097696 [from] =&gt; Array ( [name] =&gt; John Doe [id] =&gt; 505212695 ) [story] =&gt; "Text of a story I posted on my wall..." [story_tags] =&gt; Array ( [38] =&gt; Array ( [0] =&gt; Array ( [id] =&gt; 15212444 [name] =&gt; John Doe [offset] =&gt; 38 [length] =&gt; 10 [type] =&gt; user ) ) ) [type] =&gt; status [application] =&gt; Array ( [name] =&gt; Share_bookmarklet [id] =&gt; 5085647995 ) [created_time] =&gt; 2012-04-04T05:51:21+0000 [updated_time] =&gt; 2012-04-04T05:51:21+0000 [comments] =&gt; Array ( [count] =&gt; 0 ) ) </code></pre> <p>The problem is that I don't want to just find the entire collection, I want to find only those arrays that have say [message] and [story] fields, and then just find their contents and nothing else.</p> <p>I'm trying to receive a subset, two levels deep:</p> <pre><code>//this works, however, I'm only able to get the 0 array $cursor = $feeds-&gt;find( array(), array('0.story' =&gt; true) ); </code></pre> <p>How do I filter by all arrays?</p> <p>I want my end result to look like this:</p> <pre><code>Array ( [_id] =&gt; MongoId Object ( [$id] =&gt; 4f7db4dd6434e64959000000 ) [0] =&gt; Array ( [story] =&gt; "Text of a story I posted on my wall..." ) [1] =&gt; Array ( [story] =&gt; "Text of a story I posted on my wall..." ) [2] =&gt; Array ( [story] =&gt; "Text of a story I posted on my wall..." [message] =&gt; "In this case message text exists as well..." ) [3] =&gt; Array ( [message] =&gt; "Text of a message I posted on my wall..." ) etc... ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload