use of com.mongodb.client.MongoCollection in project jackrabbit-oak by apache.
the class MongoUtilsTest method createPartialIndex.
@Test
public void createPartialIndex() {
MongoConnection c = connectionFactory.getConnection();
c.getDB().dropDatabase();
MongoStatus status = new MongoStatus(c.getMongoClient(), c.getDBName());
assumeTrue(status.isVersion(3, 2));
MongoCollection collection = c.getDatabase().getCollection("test");
MongoUtils.createPartialIndex(collection, new String[] { "foo", "bar" }, new boolean[] { true, true }, "{foo:true}");
assertTrue(MongoUtils.hasIndex(collection, "_id"));
assertTrue(MongoUtils.hasIndex(collection, "foo", "bar"));
List<Document> indexes = new ArrayList<>();
collection.listIndexes().into(indexes);
assertEquals(2, indexes.size());
for (Document info : indexes) {
Document key = (Document) info.get("key");
assertNotNull(key);
if (key.keySet().contains("foo")) {
assertEquals(2, key.keySet().size());
assertEquals(1, key.get("foo"));
assertEquals(1, key.get("bar"));
Document filter = (Document) info.get("partialFilterExpression");
assertNotNull(filter);
assertEquals(Boolean.TRUE, filter.get("foo"));
}
}
c.getDB().dropDatabase();
}
use of com.mongodb.client.MongoCollection in project jackrabbit-oak by apache.
the class MongoDocumentStore method getStats.
@Nonnull
@Override
public Map<String, String> getStats() {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
List<MongoCollection<?>> all = ImmutableList.of(nodes, clusterNodes, settings, journal);
all.forEach(c -> toMapBuilder(builder, db.runCommand(new BasicDBObject("collStats", c.getNamespace().getCollectionName()), BasicDBObject.class), c.getNamespace().getCollectionName()));
return builder.build();
}
use of com.mongodb.client.MongoCollection in project spring-integration by spring-projects.
the class MongoDbOutboundGatewayTests method testWithCollectionCallbackCount.
@Test
@MongoDbAvailable
public void testWithCollectionCallbackCount() throws Exception {
Message<String> message = MessageBuilder.withPayload("").build();
MongoDbOutboundGateway gateway = createGateway();
gateway.setEntityClass(Person.class);
gateway.setCollectionNameExpression(new LiteralExpression("data"));
gateway.setCollectionCallback(MongoCollection::count);
gateway.afterPropertiesSet();
long result = (long) gateway.handleRequestMessage(message);
assertEquals(4, result);
}
use of com.mongodb.client.MongoCollection in project mongo-java-driver by mongodb.
the class UnifiedCrudHelper method executeBulkWrite.
OperationResult executeBulkWrite(final BsonDocument operation) {
MongoCollection<BsonDocument> collection = entities.getCollection(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments");
List<WriteModel<BsonDocument>> requests = arguments.getArray("requests").stream().map(value -> toWriteModel(value.asDocument())).collect(toList());
BulkWriteOptions options = new BulkWriteOptions();
for (Map.Entry<String, BsonValue> cur : arguments.entrySet()) {
switch(cur.getKey()) {
case "requests":
break;
case "ordered":
options.ordered(cur.getValue().asBoolean().getValue());
break;
default:
throw new UnsupportedOperationException("Unsupported argument: " + cur.getKey());
}
}
return resultOf(() -> toExpected(collection.bulkWrite(requests, options)));
}
use of com.mongodb.client.MongoCollection in project spring-data-mongodb by spring-projects.
the class DbRefMappingMongoConverterUnitTests method convertDocumentWithMapDBRef.
// DATAMONGO-657
@Test
void convertDocumentWithMapDBRef() {
Document mapValDocument = new Document();
mapValDocument.put("_id", BigInteger.ONE);
DBRef dbRef = mock(DBRef.class);
when(dbRef.getId()).thenReturn(BigInteger.ONE);
when(dbRef.getCollectionName()).thenReturn("collection-1");
MongoDatabase dbMock = mock(MongoDatabase.class);
MongoCollection collectionMock = mock(MongoCollection.class);
when(dbFactory.getMongoDatabase()).thenReturn(dbMock);
when(dbMock.getCollection(anyString(), eq(Document.class))).thenReturn(collectionMock);
FindIterable fi = mock(FindIterable.class);
when(fi.limit(anyInt())).thenReturn(fi);
when(fi.sort(any())).thenReturn(fi);
when(fi.first()).thenReturn(mapValDocument);
when(collectionMock.find(Mockito.any(Bson.class))).thenReturn(fi);
MapDBRef mapDBRef = new MapDBRef();
MapDBRefVal val = new MapDBRefVal();
val.id = BigInteger.ONE;
Map<String, MapDBRefVal> mapVal = new HashMap<>();
mapVal.put("test", val);
mapDBRef.map = mapVal;
Document document = new Document();
converter.write(mapDBRef, document);
Document map = (Document) document.get("map");
assertThat(map.get("test")).isInstanceOf(DBRef.class);
((Document) document.get("map")).put("test", dbRef);
MapDBRef read = converter.read(MapDBRef.class, document);
assertThat(read.map.get("test").id).isEqualTo(BigInteger.ONE);
}
Aggregations