Ask PHP master! Questions about the application of MongoDB

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.