use of org.bson.BsonValue in project mongo-java-driver by mongodb.
the class GridFSTest method arrangeGridFS.
private void arrangeGridFS(final BsonDocument arrange) {
if (arrange.isEmpty()) {
return;
}
for (BsonValue fileToArrange : arrange.getArray("data", new BsonArray())) {
BsonDocument document = fileToArrange.asDocument();
if (document.containsKey("delete") && document.containsKey("deletes")) {
for (BsonValue toDelete : document.getArray("deletes")) {
BsonDocument query = toDelete.asDocument().getDocument("q");
int limit = toDelete.asDocument().getInt32("limit").getValue();
MongoCollection<BsonDocument> collection;
if (document.getString("delete").getValue().equals("fs.files")) {
collection = filesCollection;
} else {
collection = chunksCollection;
}
if (limit == 1) {
collection.deleteOne(query);
} else {
collection.deleteMany(query);
}
}
} else if (document.containsKey("insert") && document.containsKey("documents")) {
if (document.getString("insert").getValue().equals("fs.files")) {
filesCollection.insertMany(processFiles(document.getArray("documents"), new ArrayList<BsonDocument>()));
} else {
chunksCollection.insertMany(processChunks(document.getArray("documents"), new ArrayList<BsonDocument>()));
}
} else if (document.containsKey("update") && document.containsKey("updates")) {
MongoCollection<BsonDocument> collection;
if (document.getString("update").getValue().equals("fs.files")) {
collection = filesCollection;
} else {
collection = chunksCollection;
}
for (BsonValue rawUpdate : document.getArray("updates")) {
BsonDocument query = rawUpdate.asDocument().getDocument("q");
BsonDocument update = rawUpdate.asDocument().getDocument("u");
update.put("$set", parseHexDocument(update.getDocument("$set")));
collection.updateMany(query, update);
}
} else {
throw new IllegalArgumentException("Unsupported arrange: " + document);
}
}
}
use of org.bson.BsonValue in project spring-data-mongodb by spring-projects.
the class ReactiveFindOperationSupportTests method distinctReturnsRawValuesIfReturnTypeIsBsonValue.
// DATAMONGO-1761
@Test
public void distinctReturnsRawValuesIfReturnTypeIsBsonValue() {
Consumer<BsonValue> inValues = in(new BsonString("solo"), new BsonString("skywalker"));
StepVerifier.create(template.query(Person.class).distinct("lastname").as(BsonValue.class).all()).assertNext(//
inValues).assertNext(//
inValues).verifyComplete();
}
Aggregations