List of usage examples for com.mongodb DBCollection find
public DBCursor find(final DBObject query)
From source file:ConecteMongoDB.Consultas.java
public ArrayList<Hero> buscaSide(String side) { ArrayList<Hero> resultados = new ArrayList<>(); DBCollection colecao = MongoConnection.getInstance().getDB().getCollection("heroesdata"); BasicDBObject query = new BasicDBObject("Side", side); DBCursor cursor;/* ww w.j a v a2s. c o m*/ cursor = colecao.find(query).sort(new BasicDBObject("Initial" + "." + "Strength", -1)); try { while (cursor.hasNext()) { DBObject obj = cursor.next(); String nome = (String) obj.get("Title"); String lore = (String) obj.get("Lore"); String sider = (String) obj.get("Side"); String url = (String) obj.get("Url"); Hero novoHero = new Hero(nome, lore, sider, url); resultados.add(novoHero); } } finally { cursor.close(); } //System.out.println(colecao.count(query)); //System.out.println(resultados.size()); return resultados; }
From source file:ConecteMongoDB.Consultas.java
public ArrayList<Hero> buscaFunction(String function) { ArrayList<Hero> resultados = new ArrayList<>(); DBCollection colecao = MongoConnection.getInstance().getDB().getCollection("heroesdata"); DBCursor cursor;// w w w.j a v a2 s .com BasicDBObject query = new BasicDBObject("SuggestedRoleLevels" + "." + function, new BasicDBObject("$gt", 1)); cursor = colecao.find(query).sort(new BasicDBObject("SuggestedRoleLevels" + "." + function, -1)); try { while (cursor.hasNext()) { DBObject obj = cursor.next(); String nome = (String) obj.get("Title"); String lore = (String) obj.get("Lore"); String sider = (String) obj.get("Side"); String url = (String) obj.get("Url"); Hero novoHero = new Hero(nome, lore, sider, url); resultados.add(novoHero); } } finally { cursor.close(); } return resultados; }
From source file:ConecteMongoDB.Consultas.java
public ArrayList<Hero> buscaSkill(String skill) { ArrayList<Hero> resultados = new ArrayList<>(); DBCollection colecao = MongoConnection.getInstance().getDB().getCollection("heroesdata"); DBCursor cursor;/* w w w . j a v a 2 s . com*/ BasicDBObject query = new BasicDBObject("Abilities" + "." + skill, new BasicDBObject("$gt", 1)); cursor = colecao.find(query).sort(new BasicDBObject("Abilities" + "." + "Title", -1)); try { while (cursor.hasNext()) { DBObject obj = cursor.next(); String nome = (String) obj.get("Title"); String lore = (String) obj.get("Lore"); String sider = (String) obj.get("Side"); String url = (String) obj.get("Url"); Hero novoHero = new Hero(nome, lore, sider, url); resultados.add(novoHero); } } finally { cursor.close(); } return resultados; }
From source file:dao.CocinaDAO.java
public List<Pizza> getPizza(int id) { ConexionMLab con = new ConexionMLab(); MongoClient mongo = con.getConexion(); try {//w w w . j a v a 2 s. co m DB db = mongo.getDB("pizzaplaneta"); DBCollection coleccion = db.getCollection("pedido"); BasicDBObject query = new BasicDBObject(); query.put("_id", id); DBCursor cursor = coleccion.find(query); pizzas = new ArrayList<>(); if (cursor.hasNext()) { DBObject dbo = cursor.next(); //System.out.println("si " + (String)dbo.get("username")); BasicDBList dbo1 = (BasicDBList) ((DBObject) dbo.get("productos")).get("promociones"); if (dbo1 != null) { for (Object promo : dbo1) { DBObject dbo3 = DBObject.class.cast(promo); BasicDBList dboPi = (BasicDBList) dbo3.get("pizzas"); for (Object pizza : dboPi) { recorrer(DBObject.class.cast(pizza)); } } } BasicDBList dboP1 = (BasicDBList) ((DBObject) dbo.get("productos")).get("pizzas"); if (dboP1 != null) { for (Object pizza : dboP1) { recorrer(DBObject.class.cast(pizza)); } } } } catch (Exception e) { e.printStackTrace(); } finally { mongo.close(); } return pizzas; }
From source file:dao.CocinaDAO.java
void Eingredientes(String nombre) { ConexionMLab con = new ConexionMLab(); MongoClient mongo = con.getConexion(); try {/*from ww w . j a v a2 s . c o m*/ DB db = mongo.getDB("pizzaplaneta"); DBCollection coleccion = db.getCollection("pizza"); BasicDBObject query = new BasicDBObject(); query.put("nombre", nombre); ingredientes = new ArrayList<>(); DBCursor cursor = coleccion.find(query); if (cursor.hasNext()) { DBObject dbo = cursor.next(); BasicDBList dbo2 = (BasicDBList) dbo.get("ingredientes"); if (dbo2 != null) { for (Object ing : dbo2) { DBObject dbo5 = (DBObject) ing; ingred = new Ingrediente((Integer) dbo5.get("id"), (String) dbo5.get("nombre")); ingredientes.add(ingred); } } } } catch (Exception e) { e.printStackTrace(); } finally { mongo.close(); } }
From source file:dao.CocinaDAO.java
public Integer actualizarEstado(int idPedido, String username) { int idestado; ConexionMLab con = new ConexionMLab(); MongoClient mongo = con.getConexion(); DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Date fecha = new Date(); int fields = 0; try {//from w w w . j av a2s . co m DB db = mongo.getDB("pizzaplaneta"); DBCollection coleccion = db.getCollection("pedido"); BasicDBObject query = new BasicDBObject(); query.put("_id", idPedido); DBCursor cursor = coleccion.find(query); DBObject dbo = cursor.next(); BasicDBList dbo1 = (BasicDBList) dbo.get("estados"); idestado = (Integer) ((DBObject) (dbo1.get(dbo1.size() - 1))).get("id"); gEstado = new Estado(); switch (idestado + 1) { case 1: gEstado.setId(1); gEstado.setFechaHora(df.format(fecha)); gEstado.setUsername(username); break; case 2: gEstado.setId(2); gEstado.setFechaHora(df.format(fecha)); gEstado.setUsername(username); agregarPedidoDistribuidor(2); break; case 3: gEstado.setId(2); gEstado.setFechaHora(df.format(fecha)); gEstado.setUsername(username); agregarPedidoDistribuidor(2); break; } DBObject dbo3 = new BasicDBObject(); dbo3.put("id", gEstado.getId()); dbo3.put("fechaHora", gEstado.getFechaHora()); dbo3.put("username", gEstado.getUsername()); DBObject dbo4 = new BasicDBObject(); dbo4.put("estados", dbo3); DBObject dbo5 = new BasicDBObject(); dbo5.put("$push", dbo4); coleccion.update(query, dbo5).getN(); fields = idestado + 1; } catch (Exception e) { e.printStackTrace(); } finally { mongo.close(); } return fields; }
From source file:dao.CocinaDAO.java
public Integer login(String usuario, String password) { ConexionMLab con = new ConexionMLab(); MongoClient mongo = con.getConexion(); int variable = 0; try {//from ww w .j av a 2s . co m DB db = mongo.getDB("pizzaplaneta"); DBCollection coleccion = db.getCollection("usuario"); BasicDBObject query = new BasicDBObject(); query.put("username", usuario); query.put("password", password); DBCursor cursor = coleccion.find(query); if (cursor.hasNext()) { variable = 1; } } catch (Exception e) { e.printStackTrace(); } finally { mongo.close(); } return variable; }
From source file:dao.component.TrabajadorDAO.java
@Override public ArrayList<TrabajadorTO> listatrabajadores() { ArrayList<TrabajadorTO> lista = new ArrayList<TrabajadorTO>(); DBCollection table = db.getCollection("trabajador"); BasicDBObject searchQuery = new BasicDBObject(); //searchQuery.put("name", "mkyong"); // BasicDBObject searchQuery2 // = new BasicDBObject().append("name", "mkyong-updated"); DBCursor cursor = table.find(searchQuery); while (cursor.hasNext()) { String str = cursor.next().toString(); JSONObject obj = new JSONObject(str); String fecha = obj.getJSONObject("fecha_nac").getString("$date"); Date date = new Date(Integer.parseInt(fecha.substring(0, 4)), Integer.parseInt(fecha.substring(5, 7)), Integer.parseInt(fecha.substring(8, 10))); lista.add(new TrabajadorTO(obj.getJSONObject("_id").getString("$oid"), obj.getString("nombre"), obj.getString("genero"), obj.getString("dni"), date, obj.getString("estado_civil"), obj.getString("estado"), obj.getString("cuenta"), obj.getString("seguro_invalidez"), obj.getDouble("comision"), obj.getJSONObject("idAFP").getString("$oid"), obj.getString("idCategoria"), obj.getString("idPuesto"))); }//from w ww. jav a 2s . co m return lista; }
From source file:DashboardServices.LoginService.java
/** * Retrieves representation of an instance of DashboardServices.LoginService * @return an instance of java.lang.String *//*from w ww . j av a 2 s . c o m*/ @POST @Produces(MediaType.TEXT_PLAIN) public Response getUsers(@Context UriInfo info) { String username = info.getQueryParameters().getFirst("username"); String password = info.getQueryParameters().getFirst("password"); MongoClient mongoClient; String finalOutput = "HELLO"; try { mongoClient = new MongoClient(); // Now connect to your databases DB db = mongoClient.getDB("SSKDatabase"); DBCollection coll = db.getCollection("UserCollection"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("_id", username)); obj.add(new BasicDBObject("password", password)); andQuery.put("$and", obj); //System.out.println(andQuery.toString()); DBCursor cursor = coll.find(andQuery); while (cursor.hasNext()) { finalOutput += cursor.next(); } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (finalOutput.equals("HELLO")) { return Response.status(200).entity("failure").build(); } else { return Response.status(200).entity("sucess").build(); } }
From source file:DashboardServices.LoginServiceResource.java
/** * Retrieves representation of an instance of DashboardServices.LoginServiceResource * @return an instance of java.lang.String *//*from ww w. j av a 2s .c o m*/ @GET @Produces(MediaType.TEXT_PLAIN) public Response getUsers(@Context UriInfo info) { String username = info.getQueryParameters().getFirst("username"); String password = info.getQueryParameters().getFirst("password"); MongoClient mongoClient; String finalOutput = "HELLO"; try { mongoClient = new MongoClient(); // Now connect to your databases DB db = mongoClient.getDB("SSKDatabase"); System.out.println("Connect to database successfully"); DBCollection coll = db.getCollection("UserCollection"); System.out.println("Collection mycol selected successfully"); BasicDBObject andQuery = new BasicDBObject(); List<BasicDBObject> obj = new ArrayList<BasicDBObject>(); obj.add(new BasicDBObject("_id", username)); obj.add(new BasicDBObject("password", password)); andQuery.put("$and", obj); System.out.println(andQuery.toString()); DBCursor cursor = coll.find(andQuery); if (cursor != null) { System.out.println("hai"); } while (cursor.hasNext()) { System.out.println("Entered Loop"); finalOutput += cursor.next(); } } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (finalOutput.equals("HELLO")) { System.out.println("abshah"); return Response.status(200).entity("failure").build(); } else { return Response.status(200).entity("sucess").build(); } }