List of usage examples for com.mongodb DBCollection save
public WriteResult save(final DBObject document)
From source file:fr.wseduc.gridfs.GridFSPersistor.java
License:Apache License
private void persistChunk(Message<Buffer> message, byte[] data, JsonObject json) { final Integer n = json.getInteger("n"); if (n == null) { replyError(message, "Invalid chunk number"); return;/*from w w w. jav a 2 s . c o m*/ } final String id = json.getString("_id"); if (id == null || id.trim().isEmpty()) { replyError(message, "Invalid file id"); return; } if (n == 0) { try { saveFile(json, data.length); } catch (MongoException e) { logger.error(e.getMessage(), e); replyError(message, e.getMessage()); return; } } try { DBObject chunk = BasicDBObjectBuilder.start().add("files_id", id).add("n", n).add("data", data).get(); DBCollection collection = db.getCollection(bucket + CHUNKS); collection.save(chunk); replyOK(message, new JsonObject()); } catch (RuntimeException e) { logger.error(e.getMessage(), e); replyError(message, e.getMessage()); } }
From source file:fr.wseduc.gridfs.GridFSPersistor.java
License:Apache License
private void saveFile(JsonObject json, long chunkSize) { json.putNumber("chunkSize", chunkSize); json.removeField("n"); if (json.getString("content-type") != null) { json.putString("contentType", json.getString("content-type")); json.removeField("content-type"); }//from w w w .j a va 2 s.c o m DBObject file = jsonToDBObject(json); file.put("uploadDate", new Date()); DBCollection collection = db.getCollection(bucket + FILES); collection.save(file); }
From source file:github.macrohuang.orm.mongo.core.MongoDBTemplate.java
License:Apache License
public <T> String saveOrUpdate(DBChooser dbChooser, T entry) throws MongoDataAccessException { Assert.assertNotNull(dbChooser);/*from w w w . j a v a 2 s .c om*/ Assert.assertNotNull(entry); if (Constants.coreLogEnable) LOGGER.info("Save request received:" + entry); DBCollection collection = getCollection(dbChooser); DBObject po = DBObjectUtil.convertPO2DBObject(entry); if (isOperateSuccess(collection.save(po))) { DBObjectUtil.setEntryId(po, entry); return po.get(Constants.MONGO_ID).toString(); } else { return null; } }
From source file:it.sayservice.platform.smartplanner.otp.OTPStorage.java
License:Apache License
public void storeMap(MongoTemplate template, Map<String, Object> map, String collectionName) { DBCollection collection = template.getCollection(collectionName); DBObject obj = new BasicDBObject(map); collection.save(obj); }
From source file:javawithmongo.JavaWithMongo.java
/** * @param args the command line arguments *//*from www. j a va2 s . com*/ public static void main(String[] args) throws UnknownHostException, org.json.simple.parser.ParseException { // To directly connect to a single MongoDB server (note that this will not auto-discover the primary even // if it's a member of a replica set: MongoClient mongoClient = new MongoClient(); JSONParser parser = new JSONParser(); String ss = "[{\"school\":\"Unam Cch Plantel Sur\",\"schoolType\":\"High School\"},{\"school\":\"escuela secundaria diurna 281\",\"schoolType\":\"High School\",\"startYear\":2009},{\"school\":\"John F. Kennedy High School\",\"schoolType\":\"High School\"},{\"school\":\"UNAM FMVZ\",\"schoolType\":\"College\"},{\"school\":\"Facultad de Medicina Veterinaria y Zootecnia UNAM\",\"schoolType\":\"Graduate School\"}]"; Object obj = parser.parse(ss); JSONArray array = (JSONArray) obj; System.out.println("The 2nd element of array"); System.out.println(array.get(1)); System.out.println(); DB db = mongoClient.getDB("Gigya"); DBCollection coll = db.getCollection("datos"); BasicDBObject doc = new BasicDBObject("escuela", array); coll.save(doc); // Set<String> colls = db.getCollectionNames(); // // for (String s : colls) { // System.out.println(s); // } // // // DBObject myDoc = coll.findOne(); // System.out.println(myDoc.get("nombre")); }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * /*from w w w. java 2s .co m*/ * @param tenantName * @param faSite * @param faIP * @param faPort * @author gtricomi */ public void insertFAInfo(String tenantName, String faSite, String faIP, String faPort) { DB dataBase = this.getDB(tenantName); DBCollection collezione = this.getCollection(dataBase, "faInfo"); BasicDBObject obj = new BasicDBObject(); obj.append("SiteName", faSite); obj.append("Ip", faIP); obj.append("Port", faPort); collezione.save(obj); }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * This update Federation User with element. * @param dbName/* w w w . j av a 2s . com*/ * @param tableName * @param faSite, this is the cloud Id * @param docJSON * @author gtricomi */ public void insertNetTables(String dbName, String faSite, String docJSON, double version) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, "netTables"); BasicDBObject obj = (BasicDBObject) JSON.parse(docJSON); obj.append("referenceSite", faSite); obj.append("insertTimestamp", System.currentTimeMillis()); obj.append("version", version); collezione.save(obj); }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * This update Federation User with element. * @param dbName/*from w w w .j a v a 2 s. c o m*/ * @param faSite, this is the cloud Id * @param docJSON * @author gtricomi */ public void insertSiteTables(String dbName, String faSite, String docJSON) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, "siteTables"); BasicDBObject obj = (BasicDBObject) JSON.parse(docJSON); obj.append("referenceSite", faSite); obj.append("insertTimestamp", System.currentTimeMillis()); collezione.save(obj); }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * This update Federation User with element. * @param dbName// w w w. j a v a 2s. co m * @param tableName * @param faSite, this is the cloud Id * @param docJSON * @author gtricomi */ public void insertTenantTables(String dbName, String tableName, String faSite, String docJSON) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, "TenantTables"); BasicDBObject obj = (BasicDBObject) JSON.parse(docJSON); obj.append("referenceSite", faSite); obj.append("insertTimestamp", System.currentTimeMillis()); collezione.save(obj); }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * This update Federation User with element * @param dbName//from w ww .ja v a 2 s.c o m * @param collectionName * @param docJSON */ public void insertUser(String dbName, String collectionName, String docJSON) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, collectionName); BasicDBObject obj = (BasicDBObject) JSON.parse(docJSON); String userName; userName = obj.getString("federationUser"); obj.append("_id", userName); obj.append("insertTimestamp", System.currentTimeMillis()); collezione.save(obj); }