use of org.bson.Document in project mongo-java-driver by mongodb.
the class ClusterFixture method enableMaxTimeFailPoint.
public static void enableMaxTimeFailPoint() {
assumeThat(isSharded(), is(false));
new CommandWriteOperation<BsonDocument>("admin", new BsonDocumentWrapper<Document>(new Document("configureFailPoint", "maxTimeAlwaysTimeOut").append("mode", "alwaysOn"), new DocumentCodec()), new BsonDocumentCodec()).execute(getBinding());
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class ClusterFixture method isEnterpriseServer.
@SuppressWarnings("unchecked")
public static boolean isEnterpriseServer() {
Document buildInfo = getBuildInfo();
List<String> modules = Collections.emptyList();
if (buildInfo.containsKey("modules")) {
modules = (List<String>) buildInfo.get("modules");
}
return modules.contains("enterprise");
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class UpdatePrimer method replaceDocument.
@Test
public void replaceDocument() {
assumeTrue(serverVersionAtLeast(2, 6));
// @begin: replace-document
// @code: start
db.getCollection("restaurants").replaceOne(new Document("restaurant_id", "41704620"), new Document("address", new Document().append("street", "2 Avenue").append("zipcode", "10075").append("building", "1480").append("coord", asList(-73.9557413, 40.7720266))).append("name", "Vella 2"));
// @code: end
/*
// @post: start
The replaceOne operation returns a ``UpdateResult`` which contains information about the operation.
The ``getModifiedCount`` method returns the number of documents modified.
// @post: end
*/
// @end: replace-document
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class GridFSBucketImpl method getFileByName.
private GridFSFile getFileByName(final String filename, final GridFSDownloadOptions options) {
int revision = options.getRevision();
int skip;
int sort;
if (revision >= 0) {
skip = revision;
sort = 1;
} else {
skip = (-revision) - 1;
sort = -1;
}
GridFSFile fileInfo = find(new Document("filename", filename)).skip(skip).sort(new Document("uploadDate", sort)).first();
if (fileInfo == null) {
throw new MongoGridFSException(format("No file found with the filename: %s and revision: %s", filename, revision));
}
return fileInfo;
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class GridFSBucketImpl method checkCreateIndex.
private void checkCreateIndex() {
if (!checkedIndexes) {
if (filesCollection.withDocumentClass(Document.class).withReadPreference(primary()).find().projection(new Document("_id", 1)).first() == null) {
Document filesIndex = new Document("filename", 1).append("uploadDate", 1);
if (!hasIndex(filesCollection.withReadPreference(primary()), filesIndex)) {
filesCollection.createIndex(filesIndex);
}
Document chunksIndex = new Document("files_id", 1).append("n", 1);
if (!hasIndex(chunksCollection.withReadPreference(primary()), chunksIndex)) {
chunksCollection.createIndex(chunksIndex, new IndexOptions().unique(true));
}
}
checkedIndexes = true;
}
}
Aggregations