Home  >  Article  >  Backend Development  >  请问php高手!关于mongodb的应用有关问题

请问php高手!关于mongodb的应用有关问题

WBOY
WBOYOriginal
2016-06-13 10:08:59723browse

请教php高手!关于mongodb的应用问题!
mongodb某一库中有一集合ids,其中的原始数据为db.ids.insert({'name':'user','id':0})
我想通过下面的方法实现一个自增长的id。代码如下:

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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)."<br>";//输出1    $id = $db->command($command);    echo json_encode($id)."<br>";//输出2    return $id['value']['id'];}


调用该方法并不能实现目标。输出结果为:
输出1: {"findAndModify":"ids","update":{"$inc":{"id":1}},"query":{"name":"user"},"new":true}
输出2: {"errmsg":"no such cmd","bad cmd":{"findAndModify":"ids","update":{"$inc":{"id":1}},"query":{"name":"user"},"new":true},"ok":0}

请问这是怎么回事?会不会是mongo的版本问题?

------解决方案--------------------
没用过mongodb。不知是个什么情况。
------解决方案--------------------
你的mongodb版本是?
http://www.mongodb.org/display/DOCS/findAndModify+Command

看文档是v1.3以上才支持
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn