Ask PHP master! Questions about MongoDB Application!
MongoDB a library has a collection of IDs, where the original data is Db.ids.insert ({' Name ': ' User ', ' ID ': 0})
I want to implement a self-growing ID by the following method. The code is as follows:
PHP Code
public static function Autoid ($name, $db) { $update = array (' $inc ' =>array (' id ' =>1)); $query = Array (' name ' = = $name); $command = Array (' findandmodify ' = ' IDs ', ' update ' = $update, ' query ' + $query, ' new ' =>true); echo Json_encode ($command). "
";//Output 1 $id = $db->command ($command); echo Json_encode ($id). "
";//Output 2 return $id [' value '] [' ID '];}
Calling this method does not implement the target. The output is:
Output 1: {"findandmodify": "IDs", "Update": {"$inc": {"id": 1}}, "query": {"name": "User"}, "new": true}
Output 2: {"errmsg": "No such cmd", "Bad cmd": {"findandmodify": "IDs", "Update": {"$inc": {"id": 1}}, "query": {"name": "User"}, " New ": true}," OK ": 0}
Excuse me, what's going on here? Will it be the MONGO version?
------Solution--------------------
Didn't use MongoDB. I don't know what the situation is.
------Solution--------------------
What is your version of MongoDB?
Http://www.mongodb.org/display/DOCS/findAndModify+Command
See document is v1.3 above only support