note 124329 added to mongodb.tutorial.library
| From: | wpg@php.net | Date: | Wed, 23 Oct 2019 17:40:01 +0000 |
| Subject: | note 124329 added to mongodb.tutorial.library | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-212757@lists.php.net to get a copy of this message | ||
If you have a number of JSON documents with nested elements such as 'responseId' below and
you want to know how many documents have a responseId:
{"result":{"responseId":"xyz"}}
{"result":NULL}
{"result":{"responseId":"abc"}}
I was not having luck with the following format
<?php
// trying to get the count of documents where responseId is not equal to NULL (did not work for me)
$intCount = $collection->count(['result' => ['responseId' =>
['$ne' => NULL]]]);
?>
Instead I needed to use a period between the JSON elements:
<?php
// get the count of documents where responseId is not equal to NULL
$intCount = $collection->count(['result.responseId' => ['$ne' =>
NULL]]);
?>
----
Server IP: 208.43.231.9
Probable Submitter: 82.199.157.54 (proxied: 152.19.76.33)
----
Manual Page -- http://php.net/manual/en/mongodb.tutorial.library.php
Edit -- https://master.php.net/note/edit/124329
Del: integrated -- https://master.php.net/note/delete/124329/integrated
Del: useless -- https://master.php.net/note/delete/124329/useless
Del: bad code -- https://master.php.net/note/delete/124329/bad+code
Del: spam -- https://master.php.net/note/delete/124329/spam
Del: non-english -- https://master.php.net/note/delete/124329/non-english
Del: in docs -- https://master.php.net/note/delete/124329/in+docs
Del: other reasons-- https://master.php.net/note/delete/124329
Reject -- https://master.php.net/note/reject/124329
Search -- https://master.php.net/manage/user-notes.php