为什么mongodb无法对类似数据进行排序?

时间:2019-02-18 10:08:29

标签: mongodb mongodb-query aggregation-framework bson nosql-aggregation

我正在根据用户状态对数据进行排序(当前状态为两个值0和1)。

我的mongodb查询:-

    db.users.aggregate(
    [ { '$facet': 
        { total:[ 
                    { '$match': 
                        {   '$or': [ 
                                    { name: { '$regex': /(?:)/, '$options': 'i' } },
                                    { phonenumber: { '$regex': /(?:)/, '$options': 'i' } } 
                                ] 
                        } 

                    },
                    { '$group': { _id: null, Count: { '$sum': 1 } } } 
                ], 
            users: [ 
                { '$match': 
                    { '$or':[ 
                                { name: { '$regex': /(?:)/, '$options': 'i' } }, 
                                { phonenumber: { '$regex': /(?:)/, '$options': 'i' } } 
                            ],
                    } 

                }, 
            { '$project': 
                    {   name: 1, phonenumber: 1, password: 1, created_by: 1, created: 1, 
                        planType: 1, planStart: 1, planEnd: 1, status: 1 } }, 
            { '$sort': { created: 1 } }, { '$skip': 0 }, { '$limit': 3 } ] } 
        },
        { '$unwind': '$total' }, 
        { '$project': { total: '$total.Count', users: '$users' } } 
    ]
)

当我使用创建的名称对数据进行排序时,一切都很好,但是当我使用状态对数据进行排序时,则效果不佳

当我将页面设置为= 1,即skip = 0时,假设它给出了以下ID 5c6285e07e386e5445ffc3f7、5c6285e07e386e5445ffc3f3、5c6285e07e386e5445ffc322。

然后,我设置page =2,即skip= 3,它应该skip的前3个ID,但它也为我提供了上述ID数据。

当我将每个状态值更改为不同的值时,它也可以正常工作,但是每当我将每个值更改为01active时,这给了我已经在1 as a string上获取的记录。

0 个答案:

没有答案
相关问题