0

i am having difficulty to convert mongodb shell command to php. In shell i am using

db.files.find({"username":"username",
$and:[
{'filetype': {$not : /image/}},
{'filetype':{$not:/application/}},
{'filetype':{$not:/video/}}
]

})

As you can see i am having diffculty to convert it to php. I tried few way on stack overflow but got empty result. Can anyone help on this code.

1 Answer 1

1

It should be

$db->files->find(array(
  'username' => 'username',
  '$and' => array(
    array('filetype' => array('$not' => new MongoRegex('/image/'))),
    array('filetype' => array('$not' => new MongoRegex('/application/'))),
    array('filetype' => array('$not' => new MongoRegex('/video/'))),
  ),
));

BTW you could use this tiny script, to convert JSON representations to PHP:

var_export(json_decode($jsonAsString, true));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your awesome answer. Btw how var_export(json_decode($jsonAsString, true)); How this helps to convert most of mongoshell command to php.
If you have your where in json (f.ex. '{"username":"username"}') this script would show to you how it would be in php: var_export(json_decode('{"username":"username"}', true)) => array('username' => 'username')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.