我正在使用php MongoClient()来登录(auth = true),以使用Php的mongodb“test”。 现在我想切换分贝到“test1”使用PHP没有身份验证。 它适用于mongo shell命令 - “use test1” 当我尝试使用connection-> selectdb(“test1”)在php中执行相同的操作时,它会尝试在“test1”db上验证同一用户并失败。在PHP中没有身份验证的开关db mongodb
有没有办法使用Php Mongoclient()切换db?
上mongoshell下面的代码将在测试和运行的MapReduce上test1.orders通过存储test.SampleGroupby结果验证USER1
mongo --host XXXX -u user1 -p XXXX --authenticationDatabase test
use test1; /*I don't need to authenticate user1 on test1 (test.user1 already has read/write permission on test1) */
db.orders.mapReduce(mapf, redf, {"out": {reduce: "SampleGroupby", db: "test"}, finalize: finf })
现在同样我想用PHP来实现 -
$Connection = MongoClient("mongodb://XXXX:XXXX", array("username" => user1, "password" => XXXX, "db" => test));
$Connection->test1->command(array( /*Here it tries to re authenticate user1 on test1 and fails */
"mapreduce" => orders,
"map" => $map,
"reduce" => $reduce,
"out" => array("reduce" => SampleGroupby , "db" => test),
"finalize" => $finalize
));
感谢您的回应。我明白了这一点,但问题在于,我无法获得使用mongo shell的相同结果。以确切的方案更新问题。 –