List of usage examples for com.mongodb BasicDBObjectBuilder BasicDBObjectBuilder
public BasicDBObjectBuilder()
From source file:com.aperigeek.dropvault.web.dao.MongoFileService.java
License:Open Source License
public Resource getResourceAt(Resource parent, String... path) throws ResourceNotFoundException { DBCollection col = mongo.getDataBase().getCollection("files"); DBObject obj = null;/*from w ww . j a va 2s. c o m*/ ObjectId id = parent.getId(); for (String name : path) { if ("".equals(name) || ".".equals(name)) { continue; } DBObject filter = new BasicDBObjectBuilder().add("name", name).add("parent", id).get(); obj = col.findOne(filter); if (obj == null) { throw new ResourceNotFoundException(); } id = (ObjectId) obj.get("_id"); } return buildResource(obj); }
From source file:com.aperigeek.dropvault.web.dao.MongoFileService.java
License:Open Source License
public void move(String username, Resource source, String dest) throws ResourceNotFoundException { String[] path = dest.split("/"); Resource parent = getRootFolder(username); for (int i = 0; i < path.length - 1; i++) { parent = getChild(parent, path[i]); if (parent == null) { throw new ResourceNotFoundException(); }//from w w w . j a v a2 s . c o m } DBCollection files = mongo.getDataBase().getCollection("files"); DBObject update = new BasicDBObject("$set", new BasicDBObjectBuilder().append("parent", parent.getId()) .append("name", path[path.length - 1]).get()); DBObject filter = new BasicDBObject("_id", source.getId()); DBObject current = files.findOne(filter); files.update(new BasicDBObject("_id", (ObjectId) current.get("parent")), new BasicDBObject("$set", new BasicDBObject("modificationDate", new Date()))); files.update(filter, update); files.update(new BasicDBObject("_id", parent.getId()), new BasicDBObject("$set", new BasicDBObject("modificationDate", new Date()))); }
From source file:com.aperigeek.dropvault.web.dao.user.UsersDAO.java
License:Open Source License
public boolean login(String username, String passHash) { DBCollection users = mongo.getDataBase().getCollection("users"); DBObject filter = new BasicDBObjectBuilder().add("name", username).add("password", passHash).get(); DBObject result = users.findOne(filter); if (result == null) { return false; }/*from w w w .j a va 2s .c o m*/ return true; }
From source file:com.examples.aggregation.AggregationExample.java
License:Open Source License
public Iterator<DBObject> simpleAggregation() { BasicDBObjectBuilder builder = new BasicDBObjectBuilder(); builder.push("$group"); builder.add("_id", "$manufacturer"); builder.push("num_products"); builder.add("$sum", 1); builder.pop();//from w ww . jav a 2 s. co m builder.pop(); return col.aggregate(builder.get()).results().iterator(); }
From source file:com.examples.aggregation.AggregationExample.java
License:Open Source License
public Iterator<DBObject> compoundAggregation() { BasicDBObjectBuilder builder = new BasicDBObjectBuilder(); builder.push("$group"); builder.push("_id"); builder.add("manufacturer", "$manufacturer"); builder.add("category", "$category"); builder.pop();/* www . j a va 2s . c o m*/ builder.push("num_products"); builder.add("$sum", 1); builder.pop(); builder.pop(); return col.aggregate(builder.get()).results().iterator(); }
From source file:com.examples.aggregation.AggregationExample.java
License:Open Source License
public Iterator<DBObject> sumPrices() { BasicDBObjectBuilder builder = new BasicDBObjectBuilder(); builder.push("$group"); builder.add("_id", "$manufacturer"); builder.push("sum_prices"); builder.add("$sum", "$price"); builder.pop();/*w ww. j a va 2s . c o m*/ builder.pop(); return col.aggregate(builder.get()).results().iterator(); }
From source file:com.examples.aggregation.AggregationExample.java
License:Open Source License
public Iterator<DBObject> averagePrices() { BasicDBObjectBuilder builder = new BasicDBObjectBuilder(); builder.push("$group"); builder.add("_id", "$category"); builder.push("sum_prices"); builder.add("$avg", "$price"); builder.pop();/*from w ww . java 2 s .co m*/ builder.pop(); return col.aggregate(builder.get()).results().iterator(); }
From source file:com.examples.aggregation.AggregationExample.java
License:Open Source License
public Iterator<DBObject> addToSet() { BasicDBObjectBuilder builder = new BasicDBObjectBuilder(); builder.push("$group"); builder.push("_id"); builder.add("maker", "$manufacturer"); builder.pop();/*from w ww .j a v a 2 s . c o m*/ builder.push("categories"); builder.add("$addToSet", "$category"); builder.pop(); builder.pop(); return col.aggregate(builder.get()).results().iterator(); }
From source file:com.examples.aggregation.AggregationExample.java
License:Open Source License
public Iterator<DBObject> push() { BasicDBObjectBuilder builder = new BasicDBObjectBuilder(); builder.push("$group"); builder.push("_id"); builder.add("maker", "$manufacturer"); builder.pop();//from www . j av a2 s . com builder.push("categories"); builder.add("$push", "$category"); builder.pop(); builder.pop(); return col.aggregate(builder.get()).results().iterator(); }
From source file:com.examples.aggregation.AggregationExample.java
License:Open Source License
public Iterator<DBObject> maxPrice() { BasicDBObjectBuilder builder = new BasicDBObjectBuilder(); builder.push("$group"); builder.push("_id"); builder.add("maker", "$manufacturer"); builder.pop();//from w w w . ja va 2 s. co m builder.push("maxprice"); builder.add("$max", "$price"); builder.pop(); builder.pop(); return col.aggregate(builder.get()).results().iterator(); }