MongoDB:没有添加地理空间索引

时间:2013-12-17 06:25:50

标签: mongodb indexing geospatial

我有一个mongo集合,其中每个文档都有一个'loc'数组,如下所示:

> db.trucks.findOne()
{
    "_id" : ObjectId("52afe2a9e8de3f311ec675ee"),
    "objectid" : "427856",
    "fooditems" : "Cupcakes",
    "facilitytype" : "Truck",
    "loc" : [
        37.7901490737255,
        -122.398658184604
    ],
    "priorpermit" : "0",
    "location" : {
        "latitude" : "37.7901490874965",
        "needs_recoding" : false,
        "longitude" : "-122.398658184594"
    },
    "lot" : "055",
    "cnn" : "101000",
    "status" : "REQUESTED",
    "schedule" : "http://bsm.sfdpw.org/PermitsTracker/reports/report.aspx?title=schedule&report=rptSchedule&params=permit=13MFF-0068&ExportPDF=1&Filename=13MFF-0068_schedule.pdf",
    "locationdescription" : "01ST ST: STEVENSON ST to JESSIE ST (21 - 56)",
    "latitude" : "37.7901490737255",
    "blocklot" : "3708055",
    "address" : "50 01ST ST",
    "received" : "Mar 14 2013  3:34PM",
    "applicant" : "Cupkates Bakery, LLC",
    "longitude" : "-122.398658184604",
    "expirationdate" : "2013-03-15T00:00:00",
    "permit" : "13MFF-0068",
    "y" : "2115738.283",
    "x" : "6013063.33",
    "block" : "3708"
}

当我尝试索引“loc”时,它不会被添加:

> db.trucks.ensureIndex( { loc : "2d" } )
> db.trucks.getIndexes()
[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "ns" : "food.trucks",
        "name" : "_id_"
    }
]

我做错了什么?

1 个答案:

答案 0 :(得分:0)

不应该是db.trucks.ensureIndex({loc:“2d”})?
您正在为其他一些集合创建索引。