开发者

mongoDb : How to get DB/connection reference from collection reference?

开发者 https://www.devze.com 2023-02-21 05:13 出处:网络
I have a mongodb connection making class which I cannot modify for some reason. It gives me a reference to a target mongodb collection in which I can do operations .

I have a mongodb connection making class which I cannot modify for some reason. It gives me a reference to a target mongodb collection in which I can do operations . eg.

  $myColl = mongoConnect::targetCollection($key);
  $myColl->insert( array("_id" => "SDFWERWER" ,"data" =&g开发者_运维问答t; 42 ));
// How can I get a reference to the DATABASE using $myColl, so that I can use some 
// command like :
  $myDb->command();  <--- some DB reference like this.

EDIT : i got it , $myColl->db gives reference to db value in PHP driver :)


See the PHP driver documentation for the Collection class

It shows there is a public field containing a reference to the DB ($db).

Hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消