use of org.bson.Document in project mongo-java-driver by mongodb.
the class Fixture method initializeCollection.
public static MongoCollection<Document> initializeCollection(final MongoNamespace namespace) {
MongoDatabase database = getMongoClient().getDatabase(namespace.getDatabaseName());
try {
FutureResultCallback<Document> futureResultCallback = new FutureResultCallback<Document>();
database.runCommand(new Document("drop", namespace.getCollectionName()), futureResultCallback);
futureResultCallback.get(60, SECONDS);
} catch (MongoCommandException e) {
if (!e.getErrorMessage().startsWith("ns not found")) {
throw e;
}
} catch (Throwable t) {
throw new RuntimeException(t);
}
return database.getCollection(namespace.getCollectionName());
}
use of org.bson.Document in project mongo-java-driver by mongodb.
the class Fixture method dropDatabase.
public static void dropDatabase(final String name) {
if (name == null) {
return;
}
try {
FutureResultCallback<Document> futureResultCallback = new FutureResultCallback<Document>();
getMongoClient().getDatabase(name).runCommand(new Document("dropDatabase", 1), futureResultCallback);
futureResultCallback.get(60, SECONDS);
} catch (MongoCommandException e) {
if (!e.getErrorMessage().startsWith("ns not found")) {
throw e;
}
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
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
}
Aggregations