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

数据库大概是这个样子:

{
    "_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
}
我想大声告诉你
我想大声告诉你

répondre à tous(1)
刘奇

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

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!