mongodb - How to query mongo in php? -


So I have found this simple login function which is trying to match the email address with the password in the database and Comparing it to the data entered through the user form function login ($ email, $ password) {$ m = new Mongo ("localhost"); $ M- & gt; Connect (); $ Db = $ m- & gt; the user; $ Collection = $ db- & gt; Test_collection; Echo "& lt; east & gt;"; Var_dump ($ collection-> search one (array ('name' = & gt; 'john'))); // Verify correctly var_dump ($ archive-> (array ('name' = & gt; 'joh'))); // mask cursor object by "& lt; / pre & gt;" Echo; }

I do not understand why search () only gives the cursor object answer?

This is a mango document

  array (5) {["_id"] = & gt; Object (MongoId) # 22 (1) {["$ id"] = & gt; "4d7eaa848baf84d32b000000"} ["active"] => (True) ["email"] = & gt; "John@smith.com" ["name"] = & gt; "John" ["password"] = & gt; "334c4a4c42fdb79d7ebc3e73b517e6f8"}   

How do I query a "WHERE" which will get both email and password in the same document? I can not find the correct parameters for search () and findOne () queries. What is the correct syntax in PHP?

Find should return cursor - you read more about them here To get the document from the cursor, you have to repeat it.

In your case, findone is probably the one who is not expecting many users with you since then. The same username and password FindOne function is always the highest Gives a document, so there is no need for a cursor.

To get many forecasts in your questions, just add more fields to your query array:

  var_dump ($ collection-> search one (array ('name '= & Gt;' John ',' Password '= & gt;' 334c4a4c42fdb79d7ebc3e73b51766f8 ')));   

(If this is the correct PHP - my PHP is a bit messy)

Comments