-2

I am working on a application built in PHP using MongoDB as a database. Data is organized across BSON documents into a collection in MongoDB.

I need to retrieve only those documents where field containing string value is non empty value. I searched for functions equivalent to empty and strlen functions belonging to PHP language but did not get any relevant search results.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rubin Porwal
  • 3,736
  • 1
  • 23
  • 26
  • Doesn't matter what the language is. The [`$ne`](https://docs.mongodb.com/manual/reference/operator/query/ne/) and `""` part is what is important for an non-empty string. – Neil Lunn Jun 03 '17 at 11:48
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](https://meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jun 03 '17 at 20:16

1 Answers1

0

try this,

$cursor = $collection->find(array("someField" => array('$ne' => null)));
Harisudhan. A
  • 662
  • 1
  • 6
  • 20