Add MongoDB indexing (1.4.1)

This commit is contained in:
Tobias Eidelpes 2021-04-06 18:34:39 +02:00
parent 4bad3fc48f
commit 8b4308cf1e

View File

@ -3,6 +3,7 @@ package dst.ass1.doc.impl;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Indexes;
import dst.ass1.doc.IDocumentRepository;
import dst.ass1.jpa.model.ILocation;
import org.bson.Document;
@ -19,6 +20,9 @@ public class DocumentRepository implements IDocumentRepository {
MongoDatabase mongoDatabase = mongoClient.getDatabase(MONGO_DB_NAME);
MongoCollection<Document> mongoCollection = mongoDatabase.getCollection(COLL_LOCATION_DATA);
mongoCollection.createIndex(Indexes.ascending(M_LOCATION_NAME));
mongoCollection.createIndex(Indexes.geo2dsphere(M_LOCATION_GEO));
Document document = new Document(locationProperties)
.append(I_LOCATION, location.getLocationId())
.append(M_LOCATION_NAME, location.getName());