请教php高手!关于mongodb的应用问题!
mongodb某一库中有一集合ids,其中的原始数据为db.ids.insert({'name':'user','id':0})
我想通过下面的方法实现一个自增长的id。代码如下:
<!--
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'];
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号