Mongodb field is not null delete

How to delete all documents in a collection where the field value is not equal to zero? Basically, the MySql query version will look like this:

// MySql query DELETE FROM companies WHERE createdBy != NULL // What I tried but did not work. $this->mongo->companies->remove(array('createdBy' => true)); 

I don’t even know if it is possible if anyone can help me with this, I would appreciate it;)

Thanks:)

+6
source share
1 answer

You can do this using non equals operator:

 db.companies.find( { createdBy : { $ne : null } } ); 
+7
source

Source: https://habr.com/ru/post/908623/


All Articles