@Nullable private Version getMongoVersion(DB adminDb) { final CommandResult buildInfoResult = adminDb.command("buildInfo"); if (buildInfoResult.ok()) { final BasicDBList versionArray = (BasicDBList) buildInfoResult.get("versionArray"); if (versionArray == null || versionArray.size() < 3) { LOG.debug("Couldn't retrieve MongoDB version"); return null; } final int majorVersion = (int) versionArray.get(0); final int minorVersion = (int) versionArray.get(1); final int patchVersion = (int) versionArray.get(2); return Version.forIntegers(majorVersion, minorVersion, patchVersion); } else { LOG.debug("Couldn't retrieve MongoDB buildInfo: {}", buildInfoResult.getErrorMessage()); return null; } }
private Object negate(BasicDBObject arg) { BasicDBList list = new BasicDBList(); for (Map.Entry<String, Object> entry : arg.entrySet()) { if (entry.getKey().equals("$or")) { list.add(asDBObject("$nor", entry.getValue())); } else if (entry.getKey().equals("$and")) { BasicDBList list2 = new BasicDBList(); for (Object o : ((BasicDBList) entry.getValue())) { list2.add(negate((BasicDBObject) o)); } list.add(asDBObject("$or", list2)); } else if (entry.getValue() instanceof Pattern) { list.add(asDBObject(entry.getKey(), asDBObject("$not", entry.getValue()))); } else if (entry.getValue() instanceof BasicDBObject) { list.add(negate(entry.getKey(), (BasicDBObject) entry.getValue())); } else { list.add(asDBObject(entry.getKey(), asDBObject("$ne", entry.getValue()))); } } return list.size() == 1 ? list.get(0) : asDBObject("$or", list); }
/** * Copies this instance into a new Object. * * @return a new BasicDBList with the same values as this instance */ public Object copy() { // copy field values into new object BasicDBList newobj = new BasicDBList(); // need to clone the sub obj for (int i = 0; i < size(); ++i) { Object val = get(i); if (val instanceof BasicDBObject) { val = ((BasicDBObject) val).copy(); } else if (val instanceof BasicDBList) { val = ((BasicDBList) val).copy(); } newobj.add(val); } return newobj; }
final BasicDBList list = (BasicDBList) mappedValue; if (list.size() != 0) { if (!EmbeddedMapper.shouldSaveClassName(extractFirstElement(value), list.get(0), mf)) { for (Object o : list) { if (o instanceof DBObject) {
BasicDBList notifications = (BasicDBList) f.next().get("Notification"); BasicDBObject notification = (BasicDBObject) notifications.get(0); String url = notification.get("url");
result = (client).executeScript(script); resultList = (BasicDBList) result; Assert.assertEquals("vivek", resultList.get(0)); Assert.assertEquals(1, resultList.size());
List<String> keyElementList = new ArrayList<String>; BasicDBList bDBList = (BasicDBList)basicDBObject.get("key_elements"); for(int i = 0; i < bDBList.size(); ++i){ keyElementsList.add((String)bDBList.get(i)); }
private Object parseArray(BasicDBObject basicO, String key) throws DataException { if (!isArray(key)) { throw new DataException(String.format("%s.%s is not an array!", this.collectionName, key)); } String arrayKey = key.split("\\[")[0]; String arrayIndex = key.split("\\[")[1].split("\\]")[0]; Object listCandidate = basicO.get(arrayKey); if (!(listCandidate instanceof BasicDBList)) { throw new DataException(String.format("%s.%s is not an array!", this.collectionName, key)); } return ((BasicDBList) listCandidate).get(arrayIndex); }
private Object parseArray(BasicDBObject basicO, String key) throws DataException { if (!isArray(key)) { throw new DataException(String.format("%s.%s is not an array!", this.collectionName, key)); } String arrayKey = key.split("\\[")[0]; String arrayIndex = key.split("\\[")[1].split("\\]")[0]; Object listCandidate = basicO.get(arrayKey); if (!(listCandidate instanceof BasicDBList)) { throw new DataException(String.format("%s.%s is not an array!", this.collectionName, key)); } return ((BasicDBList) listCandidate).get(arrayIndex); }
public String getFilename(String key) { DBCursor cur = audit.find(new BasicDBObject().append("auditorComments.filepath", "NewAudit6269242818132644222/withoutJS.txt")); String test = null; while (cur.hasNext()) { BasicDBObject current_object = (BasicDBObject) cur.next(); BasicDBList auditorComments = (BasicDBList) current_object.get("auditorComments"); test = ((BasicDBObject) auditorComments.get(0)).getString("filename"); System.out.println(test); } return test; }
BasicDBList bookingsList = (BasicDBList) theObj.get("bookings"); for (int i = 0; i < bookingsList.size(); i++) { //this one gets the first document BasicDBObject bookingObj = (BasicDBObject) bookingsList.get(i); //this one gets 'bookings' embedded document, which is also a list List<BasicDBObject> embeddedBookingObjList = (List<BasicDBObject>) bookingObj.get("bookings"); Date startDateTime = embeddedBookingObjList.get(0).getDate("startDateTime"); booking.setStartDateTime(startDateTime); }
static Polygon toPolygon(BasicDBList list) { GeometryFactory gf = new GeometryFactory(); LinearRing shell = gf.createLinearRing(toCoordinates((BasicDBList) list.get(0))); LinearRing[] holes = list.size() > 1 ? new LinearRing[list.size()-1] : null; for (int i = 1; i < list.size(); i++) { holes[i-1] = gf.createLinearRing(toCoordinates((BasicDBList) list.get(i))); } return new GeometryFactory().createPolygon(shell, holes); } }
BasicDBObject document = new BasicDBObject(); document.put("name", "mkyong"); document.put("age", 30); BasicDBList documentList = new BasicDBList(); documentList.add(document); DBCollection table1 = db.getCollection("user"); table1.insert(documentList.get(0)); System.out.println("Collection Inserted successfully");
static GeometryCollection toCollection(DBObject obj) { BasicDBList list = (BasicDBList) obj.get("geometries"); Geometry[] geoms = new Geometry[list.size()]; for (int i = 0; i < list.size(); i++) { geoms[i] = toGeometry((DBObject) list.get(i)); } return new GeometryFactory().createGeometryCollection(geoms); }
static MultiPolygon toMultiPolygon(DBObject obj) { GeometryFactory gf = new GeometryFactory(); BasicDBList list = (BasicDBList) obj.get("coordinates"); Polygon[] polys = new Polygon[list.size()]; for (int i = 0; i < list.size(); i++) { polys[i] = toPolygon((BasicDBList)list.get(i)); } return gf.createMultiPolygon(polys); }
static MultiLineString toMultiLineString(DBObject obj) { GeometryFactory gf = new GeometryFactory(); BasicDBList list = (BasicDBList) obj.get("coordinates"); LineString[] lines = new LineString[list.size()]; for (int i = 0; i < list.size(); i++) { lines[i] = gf.createLineString(toCoordinates((BasicDBList)list.get(i))); } return gf.createMultiLineString(lines); }
@Override public Bounds bbox(DBCollection dbcol, MongoDataset data) { MapReduceCommand mr = new MapReduceCommand( dbcol, bboxMap, bboxReduce, null, OutputType.INLINE, new BasicDBObject()); BasicDBList list = (BasicDBList) dbcol.mapReduce(mr).getCommandResult().get("results"); DBObject bbox = (DBObject) ((DBObject) list.get(0)).get("value"); return new Bounds((Double)bbox.get("x1"), (Double)bbox.get("x2"), (Double)bbox.get("y1"), (Double)bbox.get("y2")); }