Refine search
/** * Creates a new chunk of this file. Can be over-ridden, if input files need to be split into chunks using a different mechanism. * * @param id the file ID * @param currentChunkNumber the unique id for this chunk * @param writeBuffer the byte array containing the data for this chunk * @return a DBObject representing this chunk. */ protected DBObject createChunk(final Object id, final int currentChunkNumber, final byte[] writeBuffer) { return new BasicDBObject("files_id", id) .append("n", currentChunkNumber) .append("data", writeBuffer); }
@Override public AggregationPipeline lookup(final String from, final String localField, final String foreignField, final String as) { stages.add(new BasicDBObject("$lookup", new BasicDBObject("from", from) .append("localField", localField) .append("foreignField", foreignField) .append("as", as))); return this; }
ContentPackPersistenceService(final JacksonDBCollection<ContentPack, ObjectId> dbCollection) { this.dbCollection = dbCollection; try { dbCollection.createIndex(new BasicDBObject(Identified.FIELD_META_ID, 1).append(Revisioned.FIELD_META_REVISION, 1), new BasicDBObject("unique", true)); } catch (DuplicateKeyException e) { // Ignore - this can happen if this runs before the migration of old content packs } }
BasicDBObject update = new BasicDBObject().append("$push", new BasicDBObject().append("values", dboVital)); update = update.append("$set", new BasicDBObject().append("endTime", time)); collection.update( new BasicDBObject().append("_id", pageId), update, true, false);
BasicDBObject set = new BasicDBObject("$set", new BasicDBObject("age", 10)); set.append("$set", new BasicDBObject("name", "Some Name"); someCollection.update(someSearchQuery, set);
@Override public AggregationPipeline unwind(final String field, final UnwindOptions options) { BasicDBObject unwindOptions = new BasicDBObject("path", "$" + field) .append("preserveNullAndEmptyArrays", options.isPreserveNullAndEmptyArrays()); String includeArrayIndex = options.getIncludeArrayIndex(); if (includeArrayIndex != null) { unwindOptions.append("includeArrayIndex", includeArrayIndex); } stages.add(new BasicDBObject("$unwind", unwindOptions)); return this; }
ContentPackInstallationPersistenceService(final JacksonDBCollection<ContentPackInstallation, ObjectId> dbCollection) { this.dbCollection = dbCollection; dbCollection.createIndex(new BasicDBObject(ContentPackInstallation.FIELD_CONTENT_PACK_ID, 1)); dbCollection.createIndex(new BasicDBObject(ContentPackInstallation.FIELD_CONTENT_PACK_ID, 1).append(ContentPackInstallation.FIELD_CONTENT_PACK_REVISION, 1)); }
/** * Turns this group command into the DBObject format of the command. * * @return a DBObject containing the group command as a MongoDB document */ public DBObject toDBObject() { DBObject args = new BasicDBObject("ns", collectionName).append("cond", condition) .append("$reduce", reduce) .append("initial", initial); if (keys != null) { args.put("key", keys); } if (keyf != null) { args.put("$keyf", keyf); } if (finalize != null) { args.put("finalize", finalize); } return new BasicDBObject("group", args); }
@Override public Query<T> search(final String search, final String language) { final BasicDBObject op = new BasicDBObject("$search", search) .append("$language", language); this.criteria("$text").equal(op); return this; }
public DBObject toSort(List<OrderSpecifier<?>> orderBys) { BasicDBObject sort = new BasicDBObject(); for (OrderSpecifier<?> orderBy : orderBys) { Object key = orderBy.getTarget().accept(this, null); sort.append(key.toString(), orderBy.getOrder() == Order.ASC ? 1 : -1); } return sort; }
/** * Evaluates JavaScript functions on the database server. This is useful if you need to touch a lot of data lightly, in which case * network transfer could be a bottleneck. * * @param code {@code String} representation of JavaScript function * @param args arguments to pass to the JavaScript function * @return result of the command execution * @throws MongoException if the operation failed * @mongodb.driver.manual reference/method/db.eval/ db.eval() * @deprecated The eval command was deprecated in MongoDB 3.0 */ @Deprecated public CommandResult doEval(final String code, final Object... args) { DBObject commandDocument = new BasicDBObject("$eval", code).append("args", asList(args)); return executeCommand(wrap(commandDocument)); }
@Override public Object encode(final Object value, final MappedField optionalExtraInfo) { if (value != null) { Object encodedObjects = encodeObjects(((Geometry) value).getCoordinates()); return new BasicDBObject("type", geoJsonType.getType()) .append("coordinates", encodedObjects); } else { return null; } }
private byte[] getChunk(final int chunkNumber) { if (fs == null) { throw new IllegalStateException("No GridFS instance defined!"); } DBObject chunk = fs.getChunksCollection().findOne(new BasicDBObject("files_id", id).append("n", chunkNumber)); if (chunk == null) { throw new MongoException("Can't find a chunk! file id: " + id + " chunk: " + chunkNumber); } return (byte[]) chunk.get("data"); }
/** * Creates a GridFS instance for the specified bucket in the given database. Set the preferred WriteConcern on the give DB with * DB.setWriteConcern * * @param db database to work with * @param bucket bucket to use in the given database * @throws com.mongodb.MongoException if there's a failure * @see com.mongodb.WriteConcern */ public GridFS(final DB db, final String bucket) { this.database = db; this.bucketName = bucket; this.filesCollection = database.getCollection(bucketName + ".files"); this.chunksCollection = database.getCollection(bucketName + ".chunks"); // ensure standard indexes as long as collections are small try { if (filesCollection.count() < 1000) { filesCollection.createIndex(new BasicDBObject("filename", 1).append("uploadDate", 1)); } if (chunksCollection.count() < 1000) { chunksCollection.createIndex(new BasicDBObject("files_id", 1).append("n", 1), new BasicDBObject("unique", true)); } } catch (MongoException e) { //TODO: Logging } filesCollection.setObjectClass(GridFSDBFile.class); }
/** * Deals with encoding database references. * * @param name the name of the field in the document * @param ref the database reference object */ protected void putDBRef(final String name, final DBRef ref) { BasicDBObject dbRefDocument = new BasicDBObject("$ref", ref.getCollectionName()).append("$id", ref.getId()); if (ref.getDatabaseName() != null) { dbRefDocument.put("$db", ref.getDatabaseName()); } putObject(name, dbRefDocument); }
@Override public BasicDBObject convert(Environment env, TraceInfo trace, Memory arg) throws Throwable { if (arg.isNull()) return null; ForeachIterator iterator = arg.getNewIterator(env); BasicDBObject dbObject = new BasicDBObject(); while (iterator.next()) { if (iterator.getValue().isTraversable()) { dbObject.append(iterator.getStringKey(), convert(env, trace, iterator.getValue())); } else { dbObject.append(iterator.getStringKey(), Memory.unwrap(env, iterator.getValue())); } } return dbObject; }
@Test public void shouldSaveAnEntityWithNullPoints() { getDs().save(new City("New City", null)); DBObject storedCity = getDs().getCollection(City.class) .findOne(new BasicDBObject("name", "New City"), new BasicDBObject("_id", 0) .append("className", 0)); assertThat(storedCity, is(notNullValue())); assertThat(storedCity.toString(), JSONMatcher.jsonEqual("{ name: 'New City'}")); }
@Test @SuppressWarnings("unchecked") public void testCreateEntityWithBasicDBList() throws Exception { BasicDAO<TestEntity, ObjectId> dao; dao = new BasicDAO<TestEntity, ObjectId>(TestEntity.class, getDs()); TestEntity entity = new TestEntity(); List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); data.add(new BasicDBObject("type", "text") .append("data", new BasicDBObject("text", "sometext"))); entity.setData(data); dao.save(entity); final TestEntity fetched = dao.get(entity.getId()); Assert.assertEquals(entity, fetched); }
void process(final MappedClass mc, final Validation validation) { if (validation != null) { String collectionName = mc.getCollectionName(); CommandResult result = getDB() .command(new BasicDBObject("collMod", collectionName) .append("validator", parse(validation.value())) .append("validationLevel", validation.level().getValue()) .append("validationAction", validation.action().getValue()) ); if (!result.ok()) { if (result.getInt("code") == 26) { ValidationOptions options = new ValidationOptions() .validator(parse(validation.value())) .validationLevel(validation.level()) .validationAction(validation.action()); getDatabase().createCollection(collectionName, new CreateCollectionOptions().validationOptions(options)); } else { result.throwOnError(); } } } }
assertEquals("de", dbObject.get("language_override")); assertEquals(new BasicDBObject() .append("locale", "en") .append("caseLevel", true) .append("caseFirst", "upper") .append("strength", 5) .append("numericOrdering", true) .append("alternate", "shifted") .append("maxVariable", "space") .append("backwards", true) .append("normalization", true) .append("version", "57.1"), dbObject.get("collation"));