use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class CollectionHelper method create.
public void create(final String collectionName, final CreateCollectionOptions options) {
drop(namespace);
CreateCollectionOperation operation = new CreateCollectionOperation(namespace.getDatabaseName(), collectionName, WriteConcern.ACKNOWLEDGED).capped(options.isCapped()).sizeInBytes(options.getSizeInBytes()).autoIndex(options.isAutoIndex()).maxDocuments(options.getMaxDocuments());
IndexOptionDefaults indexOptionDefaults = options.getIndexOptionDefaults();
if (indexOptionDefaults.getStorageEngine() != null) {
operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(indexOptionDefaults.getStorageEngine())));
}
ValidationOptions validationOptions = options.getValidationOptions();
if (validationOptions.getValidator() != null) {
operation.validator(toBsonDocument(validationOptions.getValidator()));
}
if (validationOptions.getValidationLevel() != null) {
operation.validationLevel(validationOptions.getValidationLevel());
}
if (validationOptions.getValidationAction() != null) {
operation.validationAction(validationOptions.getValidationAction());
}
operation.execute(getBinding());
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class DropDatabaseOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument commandDocument = new BsonDocument("dropDatabase", new BsonInt32(1));
appendWriteConcernToCommand(writeConcern, commandDocument, description);
return commandDocument;
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class DropIndexOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument commandDocument = new BsonDocument("dropIndexes", new BsonString(namespace.getCollectionName())).append("index", new BsonString(indexName));
appendWriteConcernToCommand(writeConcern, commandDocument, description);
return commandDocument;
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class FindAndDeleteOperation method getCommand.
private BsonDocument getCommand(final ConnectionDescription description) {
BsonDocument commandDocument = new BsonDocument("findandmodify", new BsonString(namespace.getCollectionName()));
putIfNotNull(commandDocument, "query", getFilter());
putIfNotNull(commandDocument, "fields", getProjection());
putIfNotNull(commandDocument, "sort", getSort());
putIfNotZero(commandDocument, "maxTimeMS", getMaxTime(MILLISECONDS));
commandDocument.put("remove", BsonBoolean.TRUE);
if (serverIsAtLeastVersionThreeDotTwo(description) && writeConcern.isAcknowledged() && !writeConcern.isServerDefault()) {
commandDocument.put("writeConcern", writeConcern.asDocument());
}
if (collation != null) {
commandDocument.put("collation", collation.asDocument());
}
return commandDocument;
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class UpdateProtocol method getAsWriteCommand.
@Override
protected BsonDocument getAsWriteCommand(final ByteBufferBsonOutput bsonOutput, final int firstDocumentPosition) {
List<ByteBufBsonDocument> documents = ByteBufBsonDocument.create(bsonOutput, firstDocumentPosition);
BsonDocument updateDocument = new BsonDocument("q", documents.get(0)).append("u", documents.get(1));
if (updates.get(0).isMulti()) {
updateDocument.append("multi", BsonBoolean.TRUE);
}
if (updates.get(0).isUpsert()) {
updateDocument.append("upsert", BsonBoolean.TRUE);
}
return getBaseCommandDocument("update").append("updates", new BsonArray(singletonList(updateDocument)));
}
Aggregations