com.mongodb.BasicDBObject.append()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中com.mongodb.BasicDBObject.append()方法的一些代码示例,展示了BasicDBObject.append()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BasicDBObject.append()方法的具体详情如下:
包路径:com.mongodb.BasicDBObject
类名称:BasicDBObject
方法名:append

BasicDBObject.append介绍

[英]Add a key/value pair to this object
[中]将密钥/值对添加到此对象

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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);
}

代码示例来源:origin: MorphiaOrg/morphia

@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;
}

代码示例来源:origin: Graylog2/graylog2-server

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
  }
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: stackoverflow.com

BasicDBObject set = new BasicDBObject("$set", new BasicDBObject("age", 10));
set.append("$set", new BasicDBObject("name", "Some Name");
someCollection.update(someSearchQuery, set);

代码示例来源:origin: MorphiaOrg/morphia

@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;
}

代码示例来源:origin: Graylog2/graylog2-server

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));
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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);
}

代码示例来源:origin: MorphiaOrg/morphia

@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;
}

代码示例来源:origin: querydsl/querydsl

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;
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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));
}

代码示例来源:origin: MorphiaOrg/morphia

@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;
  }
}

代码示例来源:origin: org.mongodb/mongo-java-driver

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");
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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);
}

代码示例来源:origin: jphp-group/jphp

@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;
}

代码示例来源:origin: MorphiaOrg/morphia

@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'}"));
}

代码示例来源:origin: MorphiaOrg/morphia

@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);
}

代码示例来源:origin: MorphiaOrg/morphia

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();
      }
    }
  }
}

代码示例来源:origin: MorphiaOrg/morphia

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"));

相关文章