Guest User

Untitled

a guest
Nov 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. $data = '{ "_id": { "$oid": "59e2ff28da721533d277792c" }, "content" : {"$oid" : "59e2ff28da721533d2777312"} }';
  2. $query = json_decode($data);
  3.  
  4. $client = new MongoClient("mongodb://username:userpassword@localhost:27017", array("db" => "testdatabase"));
  5. $mDB = $client->testdatabase;
  6. $coll = $mDB->collection_test;
  7. $cursor = $coll->find($query);
  8.  
  9. $data = '{ "_id": { "$oid": "59e2ff28da721533d277792c" }, "content" : {"$oid" : "59e2ff28da721533d2777312"} }';
  10.  
  11. $bson = MongoDBBSONfromJSON($data);
  12. $query = MongoDBBSONtoPHP($bson);
  13.  
  14. $client = new MongoDBDriverManager("mongodb://username:userpassword@localhost:27017/testdatabase");
  15. $filterQuery = new MongoDBDriverQuery($query);
  16. $cursor = $mClient->executeQuery("testdatabase.collection_test", $filterQuery);
  17. return json_encode(iterator_to_array($cursor, false));
Add Comment
Please, Sign In to add comment