List of usage examples for com.mongodb DBCollection updateMulti
public WriteResult updateMulti(final DBObject query, final DBObject update)
From source file:com.servlet.SetRead.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from ww w .j a v a 2 s.com * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Notifications notifications = new Notifications(); String receiver = request.getParameter("id"); //int empId=Integer.parseInt(empIdStr); DBcon dbcon = new DBcon(); dbcon.getDbCon(); DBCollection notifyColl = dbcon.getData("notifications"); BasicDBObject update = new BasicDBObject("$set", new BasicDBObject("read", true)); BasicDBObject search = new BasicDBObject("receiver", receiver);//search object notifyColl.updateMulti(search, update); }
From source file:com.stratio.connector.mongodb.core.engine.MongoMetadataEngine.java
License:Apache License
@Override protected void alterTable(TableName tableName, AlterOptions alterOptions, Connection<MongoClient> connection) throws ExecutionException { DB db = connection.getNativeConnection().getDB(tableName.getCatalogName().getName()); DBCollection collection = db.getCollection(tableName.getName()); switch (alterOptions.getOption()) { case ADD_COLUMN: break;// w w w .j a v a2 s .com case ALTER_COLUMN: throw new MongoValidationException("Alter options is not supported"); case DROP_COLUMN: String name = alterOptions.getColumnMetadata().getName().getName(); collection.updateMulti(new BasicDBObject(), AlterOptionsUtils.buildDropColumnDBObject(name)); break; case ALTER_OPTIONS: default: throw new MongoValidationException("Alter options is not supported"); } }
From source file:framework.modules.users.client.Model.DAO.DAO_client_MG.java
/** * Funtion to modify a client and update in DB * @param db//from w w w .j a v a 2 s . c om * @param table * @param nombre * @param nuevosAnyos */ public static void update_client(client_class client) { DBCollection table = singleton.collection; BasicDBObject data = new BasicDBObject(); data.append("dni", client.getDni()); data.append("Name", client.getName()); data.append("surname", client.getSurname()); data.append("mobile", client.getMobile()); data.append("email", client.getEmail()); data.append("nick", client.getNick()); data.append("password", client.getPassword()); data.append("avatar", client.getAvatar()); data.append("state", client.getNick()); data.append("birthday", client.getBirthday().toString_DB()); data.append("age", client.getAge()); data.append("up_date", client.getUp_date().toString_DB()); data.append("antique", client.getAntique()); data.append("shopping", client.getShopping()); data.append("benefit", client.getBenefit()); data.append("premium", client.isPremium()); data.append("type", client.getType()); //Prepara para insertar un nuevo campo BasicDBObject updateclient = new BasicDBObject(); updateclient.append("$set", data); //Busca el/los registro/s con el nombre indicado BasicDBObject searchById = new BasicDBObject(); searchById.append("dni", client.getDni()); //Realiza la actualizacin table.updateMulti(searchById, updateclient); }
From source file:Modules.Client.Model.DAO.DAO_Mongo_client.java
public static void update_client(Client_class client) { DBCollection table = Singleton_app.collection; //Prepares user data to update BasicDBObject clientdata = new BasicDBObject(); clientdata.append("name", client.getName()); clientdata.append("surname", client.getSurname()); clientdata.append("birthday", client.getBirthday().toString()); clientdata.append("mobile", client.getMobile()); clientdata.append("email", client.getEmail()); clientdata.append("user", client.getUser()); clientdata.append("password", client.getPass()); clientdata.append("avatar", client.getAvatar()); clientdata.append("state", client.isState()); clientdata.append("regdate", client.getReg_date().toString()); clientdata.append("shopping", client.getShopping()); clientdata.append("premium", client.isPremium()); clientdata.append("client_type", client.getClient_type()); //Prepares to set the update BasicDBObject updateclient = new BasicDBObject(); updateclient.append("$set", clientdata); //Search for records with the desired data BasicDBObject searchById = new BasicDBObject(); searchById.append("dni", client.getDni()); //Executes the update table.updateMulti(searchById, updateclient); }
From source file:Modules.Client.Model.DAO.DAO_Mongo_client.java
public static void update_client() { DBCollection table = Singleton_app.collection; Client_class client = Singleton_client.cl; //Prepares user data to update BasicDBObject clientdata = new BasicDBObject(); clientdata.append("name", client.getName()); clientdata.append("surname", client.getSurname()); clientdata.append("birthday", client.getBirthday().toString()); clientdata.append("mobile", client.getMobile()); clientdata.append("email", client.getEmail()); clientdata.append("user", client.getUser()); clientdata.append("password", client.getPass()); clientdata.append("avatar", client.getAvatar()); clientdata.append("state", client.isState()); clientdata.append("regdate", client.getReg_date().toString()); clientdata.append("shopping", client.getShopping()); clientdata.append("premium", client.isPremium()); clientdata.append("client_type", client.getClient_type()); //Prepares to set the update BasicDBObject updateclient = new BasicDBObject(); updateclient.append("$set", clientdata); //Search for records with the desired data BasicDBObject searchById = new BasicDBObject(); searchById.append("dni", client.getDni()); //Executes the update table.updateMulti(searchById, updateclient); }
From source file:mongodb.performance.MongoDBPerformance.java
/** * @param args the command line arguments *///from w w w.j a v a2s .c om public static void main(String[] args) throws UnknownHostException, FileNotFoundException, IOException { if (args.length == 0) { System.out.println("Parmetro no informado!"); System.exit(-1); } System.out.println("Parmetro: " + args[0]); MongoClient mongoClient = new MongoClient(); //MongoClient mongoClient = new MongoClient( "54.172.218.64" , 27017 ); DB db = mongoClient.getDB("myDatabase"); DBCollection collection = db.getCollection("ads"); collection.drop(); BulkWriteOperation builder = collection.initializeUnorderedBulkOperation(); FileInputStream fileInputStream = new FileInputStream(".\\resources\\MongoDB" + args[0] + ".txt"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream)); // Insert // Time start long start = System.currentTimeMillis(); String line; while ((line = bufferedReader.readLine()) != null) { DBObject bson = (DBObject) JSON.parse(line); builder.insert(bson); } bufferedReader.close(); builder.execute(); //Time end long elapsed = System.currentTimeMillis() - start; System.out.println("[insert] Time elapsed: " + elapsed + " ms"); // Update // Time start start = System.currentTimeMillis(); collection.updateMulti(new BasicDBObject(), new BasicDBObject("$set", new BasicDBObject().append("ano", 2006))); // Time end elapsed = System.currentTimeMillis() - start; System.out.println("[update] Time elapsed: " + elapsed + " ms"); // Select // Time start start = System.currentTimeMillis(); BasicDBObject keys = new BasicDBObject(); keys.put("_id", 1); keys.put("modeloCarro.marca", 1); keys.put("modeloCarro.nome", 1); keys.put("uf", 1); keys.put("placa_carro", 1); keys.put("qtd_portas", 1); keys.put("cambio", 1); keys.put("combustivel", 1); keys.put("cor", 1); keys.put("km", 1); keys.put("valor", 1); keys.put("detalhe", 1); BasicDBObject sort = new BasicDBObject("_id", 1); DBCursor cursor = collection.find(new BasicDBObject(), keys).sort(sort); while (cursor.hasNext()) { cursor.next(); } // Time end elapsed = System.currentTimeMillis() - start; System.out.println("[select] Time elapsed: " + elapsed + " ms"); // Delete // Time start start = System.currentTimeMillis(); collection.remove(new BasicDBObject()); // Time end elapsed = System.currentTimeMillis() - start; System.out.println("[delete] Time elapsed: " + elapsed + " ms"); }
From source file:nosqltools.UpdatePanel.java
protected void executeUpdateQuery(DBCollection collection) { BasicDBObject query = null;/*from ww w . j a va2s . c om*/ //this.parent = parent; this.QueryString = ""; QueryString = Initializations.SET_SYNTAX + tfNewField.getText() + " = " + tfNewValue.getText() + "\n" + Initializations.WHERE_SYNTAX + tfSearchField.getText() + " = " + tfSearchValue.getText(); query = getSearchQuery(tfSearchField.getText(), tfSearchValue.getText()); NoOfDocumentsUpdated = collection.find(query).count(); try { collection.updateMulti(this.getSearchQuery(tfSearchField.getText(), tfSearchValue.getText()), this.getNewDocument(tfNewField.getText(), tfNewValue.getText())); } catch (Exception exp) { System.out.println("You are here"); exp.getMessage(); exp.printStackTrace(); } }
From source file:org.springframework.data.document.mongodb.MongoTemplate.java
License:Apache License
protected WriteResult doUpdate(final String collectionName, final Query query, final Update update, final Class<?> entityClass, final boolean upsert, final boolean multi) { return execute(collectionName, new CollectionCallback<WriteResult>() { public WriteResult doInCollection(DBCollection collection) throws MongoException, DataAccessException { DBObject queryObj = query.getQueryObject(); DBObject updateObj = update.getUpdateObject(); String idProperty = "id"; if (null != entityClass) { idProperty = getPersistentEntity(entityClass).getIdProperty().getName(); }//from w w w . ja v a2 s .c o m for (String key : queryObj.keySet()) { if (idProperty.equals(key)) { // This is an ID field queryObj.put(ID, mongoConverter.maybeConvertObject(queryObj.get(key))); queryObj.removeField(key); } else { queryObj.put(key, mongoConverter.maybeConvertObject(queryObj.get(key))); } } for (String key : updateObj.keySet()) { updateObj.put(key, mongoConverter.maybeConvertObject(updateObj.get(key))); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("calling update using query: " + queryObj + " and update: " + updateObj + " in collection: " + collectionName); } WriteResult wr; if (writeConcern == null) { if (multi) { wr = collection.updateMulti(queryObj, updateObj); } else { wr = collection.update(queryObj, updateObj); } } else { wr = collection.update(queryObj, updateObj, upsert, multi, writeConcern); } handleAnyWriteResultErrors(wr, queryObj, "update with '" + updateObj + "'"); return wr; } }); }
From source file:spntoolsdata.crud.servispnCrud.java
public void updateClient(MongoClient mongo, Cliente antiguo, Cliente actualizado) { DB db = mongo.getDB("dbservispntools"); DBCollection DBCliente = db.getCollection("Clientes"); DBObject query = antiguo.getDBObjectCliente(); DBObject update = new BasicDBObject(); update.put("$set", actualizado.getDBObjectCliente()); DBCliente.updateMulti(query, update); }