MongoDB查找最大值为什么得到的是null
我想大声告诉你
我想大声告诉你 2017-05-02 09:22:17
0
1
472

数据库大概是这个样子:

{
    "_id" : ObjectId("57d248bd43be573cb0530d00"),
    "url" : "www.baidu.com",
    "shorterUrlNum" : 1
}

/* 2 */
{
    "_id" : ObjectId("57d248d843be573cb0530d01"),
    "url" : "www.baidu.com",
    "shorterUrlNum" : 1
}

/* 3 */
{
    "_id" : ObjectId("57d2490d01ddf93cb4723f8b"),
    "url" : "www.baidu.com",
    "shorterUrlNum" : 1
}

/* 4 */
{
    "_id" : ObjectId("57d24ad4a8305e3cc9851d6d"),
    "url" : "www.baidu.com",
    "shorterUrlNum" : 1
}

使用命令

db.getCollection('sites').aggregate([
                {
                    $group: {
                        _id: 'max',
                        max: {'$max': '$shorterUrl'}
                    }
                }])

为什么得出的是null这个最大值?

{
    "_id" : "max",
    "max" : null
}
我想大声告诉你
我想大声告诉你

全部回复(1)
刘奇

你的 document 里根本没有 $shorterUrl 这个字段啊。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!