List of usage examples for com.mongodb.client MongoDatabase getCollection
MongoCollection<Document> getCollection(String collectionName);
From source file:bariopendatalab.db.DBAccess.java
public void insert(String type, String description, String address, String note, Document loc) { Document doc = new Document("type", type); if (description != null) { doc.append("description", description); }/* ww w . j ava2 s . com*/ if (address != null) { doc.append("address", address); } if (note != null) { doc.append("note", note); } if (loc != null) { loc.append("loc", loc); } MongoDatabase database = client.getDatabase(DBNAME); MongoCollection<Document> collection = database.getCollection(COLLNAME); collection.insertOne(doc); }
From source file:bariopendatalab.db.DBAccess.java
public void insertDocument(Document doc) { MongoDatabase database = client.getDatabase(DBNAME); MongoCollection<Document> collection = database.getCollection(COLLNAME); collection.insertOne(doc);//from ww w .j a v a2s . com }
From source file:bariopendatalab.db.DBAccess.java
public void insertMunicipi(Document doc) { MongoDatabase database = client.getDatabase(DBNAME); MongoCollection<Document> collection = database.getCollection(COLLMUNICIPI); collection.insertOne(doc);/* w w w. ja v a 2 s. c o m*/ }
From source file:bariopendatalab.db.DBAccess.java
public String findByType(String type, int offset, int size) throws Exception { MongoDatabase database = client.getDatabase(DBNAME); MongoCollection<Document> collection = database.getCollection(COLLNAME); FindIterable<Document> documents = collection.find(new Document().append("type", type)).skip(offset) .limit(size);//from w w w .java2 s . c o m List<Document> list = new ArrayList<>(); for (Document doc : documents) { list.add(doc); } Document response = new Document(); response.append("size", list.size()); response.append("results", list); return response.toJson(); }
From source file:bariopendatalab.db.DBAccess.java
public String poiByMunicipio(int id) throws Exception { MongoDatabase database = client.getDatabase(DBNAME); MongoCollection<Document> collMunicipi = database.getCollection(COLLMUNICIPI); Document municipioDoc = collMunicipi.find(new Document().append("properties.OBJECTID", id)).first(); MongoCollection<Document> collection = database.getCollection(COLLNAME); FindIterable<Document> documents = collection.find(new Document("geometry", new Document("$geoWithin", new Document("$geometry", municipioDoc.get("geometry"))))); List<Document> list = new ArrayList<>(); for (Document doc : documents) { list.add(doc);/*from w w w . j av a 2 s.co m*/ } Document response = new Document(); response.append("size", list.size()); response.append("results", list); return response.toJson(); }
From source file:bariopendatalab.db.DBAccess.java
public List<Document> poiListByMunicipio(int id) throws Exception { MongoDatabase database = client.getDatabase(DBNAME); MongoCollection<Document> collMunicipi = database.getCollection(COLLMUNICIPI); Document municipioDoc = collMunicipi.find(new Document().append("properties.OBJECTID", id)).first(); MongoCollection<Document> collection = database.getCollection(COLLNAME); FindIterable<Document> documents = collection.find(new Document("geometry", new Document("$geoWithin", new Document("$geometry", municipioDoc.get("geometry"))))); List<Document> list = new ArrayList<>(); for (Document doc : documents) { list.add(doc);/*ww w .j ava 2 s . com*/ } return list; }
From source file:bariopendatalab.db.DBAccess.java
public String getMunicipi() throws Exception { MongoDatabase database = client.getDatabase(DBNAME); MongoCollection<Document> collection = database.getCollection(COLLMUNICIPI); FindIterable<Document> documents = collection.find(); List<Document> list = new ArrayList<>(); for (Document doc : documents) { list.add(doc);//from w w w. ja v a2 s . co m } Document response = new Document(); response.append("size", list.size()); response.append("results", list); return response.toJson(); }
From source file:be.nille.blog.mongo.author.MongoAuthorService.java
public MongoAuthorService(final MongoDatabase database) { this.collection = database.getCollection("author"); }
From source file:be.nille.blog.mongo.category.MongoCategoryService.java
public MongoCategoryService(final MongoDatabase database) { this.collection = database.getCollection("category"); }
From source file:be.nille.blog.mongo.post.MongoPostService.java
public MongoPostService(final MongoDatabase database) { this.database = database; this.collection = database.getCollection("post"); }