mongodb objectId的转换

作者: admin 日期: 2017-07-14 14:36:47 人气: - 评论: 0

调用mongodb command接口查询返回的objectid是一个对象

          "_id": {

            "timestamp": 1499995789,

            "machineIdentifier": 11168948,

            "processIdentifier": -31655,

            "counter": 11459245,

            "time": 1499995789000,

            "date": 1499995789000,

            "timeSecond": 1499995789

          },

为了获得字符串格式的objectid,特意研究了下objectId的bson结构


了解了object Bson很容易得出一个php的转换代码


    //转换objectid

    public function convertId($objectid){

        $ret ="";


        $ret.= dechex($objectid['timestamp']);

        $ret.= dechex($objectid['machineIdentifier']);

        $ret.=  substr(dechex($objectid['processIdentifier']),-4) ;

        $ret.= dechex($objectid['counter']);        

        return $ret;

    }


相关内容

发表评论
更多 网友评论0 条评论)
暂无评论

Copyright © 2012-2014 我的代码板 Inc. 保留所有权利。

页面耗时0.0254秒, 内存占用1.82 MB, 访问数据库12次

闽ICP备15009223号-1