Mongo大于比较返回0

时间:2017-12-02 03:43:48

标签: mongodb

我试图统计所有车队总数超过1000的汽车经销商。这是我写的代码,然而,它返回0并且我知道这个数据集中有相当多的记录超过1000。

db.Car_Dealership.find({Totalfleetunits : {$gte: 1000} }).count()

这是我的数据库中的内容示例,两个记录的总车队数超过1000.任何想法为什么它返回0?

     "_id" : ObjectId("5a203ab0b9574375830354d4"),
        "2016rank" : 6,
        "Dealershipgroupname" : "Hendrick Automotive Group",
        "Address" : "6000 Monroe Road",
        "City/State/Zip" : "Charlotte, NC 28212",
        "Phone" : "(704) 568-5550",
        "Companywebsite" : "www.hendrickauto.com",
        "Topexecutive" : "Rick Hendrick",
        "Topexecutivetitle" : "chairman",
        "Totalnewretailunits" : "117,946",
        "Totalusedunits" : "88,458",
        "Totalfleetunits" : "4,646",
        "Totalwholesaleunits" : "56,569",
        "Total_units" : "267,619",
        "Total_number_of _dealerships" : 103,
        "Grouprevenuealldepartments*" : "$8,551,253,132",
        "2015rank" : 6
}
{
        "_id" : ObjectId("5a203ab0b9574375830354d5"),
        "2016rank" : 5,
        "Dealershipgroupname" : "Sonic Automotive Inc.?",
        "Address" : "4401 Colwick Road",
        "City/State/Zip" : "Charlotte, NC 28211",
        "Phone" : "(704) 566-2400",
        "Companywebsite" : "www.sonicautomotive.com",
        "Topexecutive" : "B. Scott Smith",
        "Topexecutivetitle" : "CEO",
        "Totalnewretailunits" : "134,288",
        "Totalusedunits" : "119,174",
        "Totalfleetunits" : "1,715",
        "Totalwholesaleunits" : "35,098",
        "Total_units" : "290,275",
        "Total_number_of _dealerships" : 112,
        "Grouprevenuealldepartments*" : "$9,731,778,000",
        "2015rank" : 4

1 个答案:

答案 0 :(得分:0)

这是因为Totalfleetunits的值为stringType

现在要解决您的问题,您必须选择。

选项1:

您可以将Totalfleetunits的架构更改为Number的类型,并将所有文档Totalfleetvalues值从字符串更改为数字。喜欢,

  

" Totalfleetunits":" 4,646"需要改变" Totalfleetunits"   :" 4646"

选项2:

您可以在查询中使用javascript首先从您的值中删除,,然后检查Totalfleetunits的{​​{1}}值。只需更改一行代码,如下所示。

greater than or equal to ( >= )