I have the following code for running a mongo query, Where the ‘mongotester’ is the DB name and ‘categories’ is the collection name
I am using PECL mongodb library
$m = new Mongo();
$db = $m->selectDB('mongotester');
$a = $db->execute('return mongotester.categories.count();');
echo "<pre>";
var_dump($a);
echo "<pre>";
When I am running this, I am getting the following error,
array(3) {
["errno"]=>
float(-3)
["errmsg"]=>
string(78) "invoke failed: JS Error: ReferenceError: mongotester is not defined nofile_a:0"
["ok"]=>
float(0)
}
Please help me to correct this.
thanks
Rather than trying to execute() javascript for a count, you can reference the collection directly, eg:
The var_dump in this case is just going to show int(0) unless you’ve actually inserted some data into the categories collection.