Mongodb Classroom image

Anil  Bist / Professional / DataBase

 
To post your Question Join Classroom
 
Lesson Topics's No:-  ||
Lessons:-Create a 2dsphere Index

2dsphere Index

Create a 2dsphere Index

db.collection.createIndex() method is used to create a  2dsphere index.  The blueprint of a 2dsphere index :
 

db.collection.createIndex ( { <location field> : "2dsphere"  } )

 

Here, the  location field  is the key and  2dsphere  is the type of the index. In the following example we are going to create a  2dsphre  index in the  places collection.

db . places.insert (
{
loc : {  type:  "Point",  coordinates: [ -73.97, 40.77  ] },
name:  "Central Park",
category :  "Parks"
})

 

The following operation will create 2dsphere index on the loc field of places collection.

db.places.createIndex ( {  loc : "2dsphere"  } )

 

 
 
 
image
Anil  Bist

Skills    Mongodb

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)