This may be a very easy thing to do, but I'm pretty new to MongoDB and am having trouble making this word right.
I'm pulling leads from a database, and I only want it to pull records where the email field is not empty. I've tried putting in the statement to skip the record if it's not null, but there are many fields that aren't null, but don't have any characters in them, either. Here is my MongoDB query:
$records = $dbh->find('email' => array('$ne' => null))->limit(2000);
I also tried 'email' => array('$ne' => ''))
but that didn't do the trick either.
Is there a simple way to do this? I know in MySQL it would be a simple where email != ""
but I'm still learning my way around Mongo :) Thanks!
Try this, you are enclosing into array improperly
$records = $dbh->find(array("email" => array('$ne' => null)))->limit(2000);
Ok, I just figured out a decent way, and will post it for any other "noob" like me who's having the same problem :)
I used '$nin' with an array and it fixed the problem. Here's my query now:
$records = $dbh->find(array("email" => array('$nin' => array(' ','',null))))->limit(2000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With