Results 1 to 2 of 2

Thread: Difference in the index when using @CompoundIndex and creating with ensureIndex

  1. #1
    Join Date
    Sep 2007
    Posts
    4

    Default Difference in the index when using @CompoundIndex and creating with ensureIndex

    Hi,
    I'm using Spring Data 1.0.0.M5 with Mongo 2.0.1 and I notice that there is a difference in the index that gets created when I use @CompoundIndex and when I use DB.ensureIndex. My intent is to create a compound geoSpatialIndex using the 'loc' and 'type' fields in my document. The loc field has the lon/lat coords that I am indexing on. The type field is just a String field.
    When I use the following @CompoundIndex annotation:
    @CompoundIndexes(value={
    @CompoundIndex(name="location_type_idx", def="{'loc' : '2d', 'type':1}")
    })

    the index that is created in Mongo is:
    { "v" : 1, "key" : { "loc" : "2d", "type" : NumberLong(1) }, "ns" : "myCollection.xyz", "name" : "location_type_idx", "dropDups" : false, "sparse" : false }

    If I use the following code to create the index,
    DB db
    Mongo m;
    m = new Mongo(...);
    db = m.getDB(...);
    db.getCollection("myCollection").ensureIndex(new BasicDBObject("loc","2d").append("type",1));

    the index that is created in Mongo is:
    { "v" : 1, "key" : { "loc" : "2d", "type" : 1 }, "ns" : "myCollection.xyz", "name" : "loc_2d_type_1" }


    Note that the first one has "type" : NumberLong(1) and the second has "type" : 1

    The problem that I have is that the first index,
    { "v" : 1, "key" : { "loc" : "2d", "type" : NumberLong(1) }, "ns" : "myCollection.xyz", "name" : "location_type_idx", "dropDups" : false, "sparse" : false }

    doesn't seem to work. I get a NullPointerException on line 495 in MongoTemplate.geoNear.

    Does anyone know what I am doing wrong here?

    Thanks for any help in advance.

    Richard

  2. #2
    Join Date
    Apr 2006
    Location
    Dresden, Germany
    Posts
    493

    Default

    I don't think the NPE is related to the indexes getting created slightly different. Would you mind upgrading to SD MongoDB 1.0 GA. We have fixed quite a few [0], [1] issues in geoNear(…) with that release.

    [0] https://jira.springsource.org/browse/DATAMONGO-336
    [1] https://jira.springsource.org/browse/DATAMONGO-341

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •