use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class GridFSBucketImpl method delete.
@Override
public void delete(final BsonValue id) {
DeleteResult result = filesCollection.deleteOne(new BsonDocument("_id", id));
chunksCollection.deleteMany(new BsonDocument("files_id", id));
if (result.wasAcknowledged() && result.getDeletedCount() == 0) {
throw new MongoGridFSException(format("No file found with the id: %s", id));
}
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class CrudTest method shouldPassAllOutcomes.
@Test
public void shouldPassAllOutcomes() {
BsonDocument outcome = helper.getOperationResults(definition.getDocument("operation"));
BsonDocument expectedOutcome = definition.getDocument("outcome");
assertEquals(description, expectedOutcome.get("result"), outcome.get("result"));
if (expectedOutcome.containsKey("collection")) {
assertCollectionEquals(expectedOutcome.getDocument("collection"));
}
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class CrudTest method setUp.
@Before
public void setUp() {
super.setUp();
List<BsonDocument> documents = new ArrayList<BsonDocument>();
for (BsonValue document : data) {
documents.add(document.asDocument());
}
getCollectionHelper().insertDocuments(documents);
collection = database.getCollection(getClass().getName(), BsonDocument.class);
helper = new JsonPoweredCrudTestHelper(description, collection);
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class JsonPoweredCrudTestHelper method getOperationResults.
BsonDocument getOperationResults(final BsonDocument operation) {
String name = operation.getString("name").getValue();
BsonDocument arguments = operation.getDocument("arguments");
String methodName = "get" + name.substring(0, 1).toUpperCase() + name.substring(1) + "Result";
try {
Method method = getClass().getDeclaredMethod(methodName, BsonDocument.class);
return (BsonDocument) method.invoke(this, arguments);
} catch (NoSuchMethodException e) {
throw new UnsupportedOperationException("No handler for operation " + methodName);
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof AssumptionViolatedException) {
throw (AssumptionViolatedException) e.getTargetException();
}
if (e.getTargetException() instanceof MongoException) {
throw (MongoException) e.getTargetException();
}
throw (RuntimeException) e.getTargetException();
} catch (IllegalAccessException e) {
throw new UnsupportedOperationException("Invalid handler access for operation " + methodName);
}
}
use of org.bson.BsonDocument in project mongo-java-driver by mongodb.
the class DBTest method shouldCreateCollectionWithTheSetCollation.
@Test
public void shouldCreateCollectionWithTheSetCollation() {
assumeThat(serverVersionAtLeast(3, 4), is(true));
// Given
collection.drop();
Collation collation = Collation.builder().locale("en").caseLevel(true).collationCaseFirst(CollationCaseFirst.OFF).collationStrength(CollationStrength.IDENTICAL).numericOrdering(true).collationAlternate(CollationAlternate.SHIFTED).collationMaxVariable(CollationMaxVariable.SPACE).backwards(true).build();
DBObject options = BasicDBObject.parse("{ collation: { locale: 'en', caseLevel: true, caseFirst: 'off', strength: 5," + "numericOrdering: true, alternate: 'shifted', maxVariable: 'space', backwards: true }}");
// When
database.createCollection(collectionName, options);
BsonDocument collectionCollation = getCollectionInfo(collectionName).getDocument("options").getDocument("collation");
// Then
BsonDocument collationDocument = collation.asDocument();
for (String key : collationDocument.keySet()) {
assertEquals(collationDocument.get(key), collectionCollation.get(key));
}
// When - collation set on the database
database.getCollection(collectionName).drop();
database.createCollection(collectionName, new BasicDBObject("collation", BasicDBObject.parse(collation.asDocument().toJson())));
collectionCollation = getCollectionInfo(collectionName).getDocument("options").getDocument("collation");
// Then
collationDocument = collation.asDocument();
for (String key : collationDocument.keySet()) {
assertEquals(collationDocument.get(key), collectionCollation.get(key));
}
}
Aggregations