Start the mongod server first, and open a shell client: usehahadb. haha. insert ({& #039; a & #039;: & #039; aaa & #039;}) db. haha. find () {& #039; a & #039;: & #039; aaa & #039;} added successfully to open another shell client: usehahadb. haha. find () confirm the input {& #039; a & #039 ;:& #039 ;... start the mongod server first;
Open a shell client:
Use haha
Db. haha. insert ({'A': 'aaa '})
Db. haha. find ()
{'A': 'aaa '}// Added successfully
Open another shell client:
Use haha
Db. haha. find () // confirm the input.
{'A': 'aaa '}// Valid indeed
It can be seen that the shell client has an effect.
The following is the php code:
$ M = new clients client ();
$ Jihe = $ m-> db-> haha;
$ Cursor = $ jihe-> find ();
Foreach ($ cursor as $ item ){
Var_dump ($ item); // nothing, empty data
}
Then modify the php code:
$ M = new clients client ();
$ Jihe = $ m-> db-> haha;
$ Doc = array ('B' => 'bbb ');
$ Jihe-> insert ($ doc );// Php tries to insert data.
$ Cursor = $ jihe-> find ();
Foreach ($ cursor as $ item ){
Var_dump ($ item); // this time only{'B': 'bbb '}Data, not set in shell{'A': 'aaa '}
}
What's going on? All operations initiated for the same database. How is the difference between shell client access and php access?
Reply content:
Start the mongod server first;
Open a shell client:
Use haha
Db. haha. insert ({'A': 'aaa '})
Db. haha. find ()
{'A': 'aaa '}// Added successfully
Open another shell client:
Use haha
Db. haha. find () // confirm the input.
{'A': 'aaa '}// Valid indeed
It can be seen that the shell client has an effect.
The following is the php code:
$ M = new clients client ();
$ Jihe = $ m-> db-> haha;
$ Cursor = $ jihe-> find ();
Foreach ($ cursor as $ item ){
Var_dump ($ item); // nothing, empty data
}
Then modify the php code:
$ M = new clients client ();
$ Jihe = $ m-> db-> haha;
$ Doc = array ('B' => 'bbb ');
$ Jihe-> insert ($ doc );// Php tries to insert data.
$ Cursor = $ jihe-> find ();
Foreach ($ cursor as $ item ){
Var_dump ($ item); // this time only{'B': 'bbb '}Data, not set in shell{'A': 'aaa '}
}
What's going on? All operations initiated for the same database. How is the difference between shell client access and php access?
Speculation: shell is connectedhaha
Php is connecteddb
This is Two database spaces.
Open a shell client and enter the command
show dbs
Besides haha, is there a db? If Yes
$jihe = $m->db->haha;
Should be changed
$jihe = $m->haha->haha;
If it is No, (vendors) php has not been touched for many years.
Make sure you are connected to the same server and database