Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb field not null delete

Tags:

mongodb

How do I remove all documents in a collection where a field's value isn't null? Basically the MySql query version would be 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 could help me with this I would appreciate it ;)

Thanks :)

like image 263
randomKek Avatar asked Feb 16 '12 14:02

randomKek


1 Answers

You can do it easy via not equal operator:

db.companies.find( { createdBy : { $ne : null } } );
like image 61
Andrew Orsich Avatar answered Nov 12 '22 11:11

Andrew Orsich