Example usage for org.springframework.data.mongodb.core.index GeoSpatialIndexType GEO_2DSPHERE

List of usage examples for org.springframework.data.mongodb.core.index GeoSpatialIndexType GEO_2DSPHERE

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.index GeoSpatialIndexType GEO_2DSPHERE.

Prototype

GeoSpatialIndexType GEO_2DSPHERE

To view the source code for org.springframework.data.mongodb.core.index GeoSpatialIndexType GEO_2DSPHERE.

Click Source Link

Document

2D Index for GeoJSON-formatted data over a sphere.

Usage

From source file:example.springdata.mongodb.fluent.ApplicationConfiguration.java

@Bean
CommandLineRunner init(MongoTemplate template) {

    return (args) -> {

        if (template.collectionExists(COLLECTION)) {
            template.dropCollection(COLLECTION);
        }/*from  www.  j  ava 2 s  . c  o  m*/

        GeospatialIndex index = new GeospatialIndex("homePlanet.coordinates") //
                .typed(GeoSpatialIndexType.GEO_2DSPHERE) //
                .named("planet-coordinate-idx");

        template.createCollection(COLLECTION);
        template.indexOps(SWCharacter.class).ensureIndex(index);

        Planet alderaan = new Planet("alderaan", new Point(-73.9667, 40.78));
        Planet stewjon = new Planet("stewjon", new Point(-73.9836, 40.7538));
        Planet tatooine = new Planet("tatooine", new Point(-73.9928, 40.7193));

        Jedi anakin = new Jedi("anakin", "skywalker");
        anakin.setHomePlanet(tatooine);

        Jedi luke = new Jedi("luke", "skywalker");
        luke.setHomePlanet(tatooine);

        Jedi leia = new Jedi("leia", "organa");
        leia.setHomePlanet(alderaan);

        Jedi obiWan = new Jedi("obi-wan", "kenobi");
        obiWan.setHomePlanet(stewjon);

        Human han = new Human("han", "solo");

        template.save(anakin, COLLECTION);
        template.save(luke, COLLECTION);
        template.save(leia, COLLECTION);
        template.save(obiWan, COLLECTION);
        template.save(han, COLLECTION);
    };
}

From source file:com.traffitruck.service.MongoDAO.java

@Autowired
public MongoDAO(MongoTemplate mongoTemplate) {
    this.mongoTemplate = mongoTemplate;
    // Creates an index on the specified field if the index does not already exist
    mongoTemplate.indexOps(Load.class)
            .ensureIndex(new GeospatialIndex("sourceLocation").typed(GeoSpatialIndexType.GEO_2DSPHERE));
    mongoTemplate.indexOps(Load.class)
            .ensureIndex(new GeospatialIndex("destinationLocation").typed(GeoSpatialIndexType.GEO_2DSPHERE));
    mongoTemplate.indexOps(Truck.class).ensureIndex(new Index("licensePlateNumber", Direction.ASC).unique());
    mongoTemplate.indexOps(LoadsUser.class).ensureIndex(new Index("username", Direction.ASC).unique());
    mongoTemplate.indexOps(LoadsUser.class).ensureIndex(new Index("email", Direction.ASC).unique());
}