1

i am trying to do sth like this

db.points.ensureIndex( { <location field> : "2dsphere" } )

http://docs.mongodb.org/manual/core/2dsphere/

via C# driver. but the API looks like only take the "key" as parameter, no way to specify the type

http://api.mongodb.org/csharp/current/html/3871579f-5b7c-1d9f-e66d-2403c9280e80.htm

any idea how can o do it via driver?

thanks

jojo
  • 13,583
  • 35
  • 90
  • 123

2 Answers2

1

Let's say you have the field called 'location' which contains the 'type' and the 'coordinates', i.e. it looks like the following:

{ _id : ...,
  ...,
  'location' : {
         'type' : 'Point',
         'coordinates' : [ longValue, latValue]
   }
}

In order to create a 2dsphere index over the 'location' field, we do it as:

Collection.CreateIndex(IndexKeys.GeoSpatialSpherical("location"));
displayName
  • 13,888
  • 8
  • 60
  • 75
0

key is the whole object

"{ "Location" : "2dsphere" }"

i have wrong understanding

post here in case someone encounter same issue as i did

jojo
  • 13,583
  • 35
  • 90
  • 123