Search in sources :

Example 86 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class Criteria method orOperator.

/**
 * Creates a criteria using the {@code $or} operator for all of the provided criteria.
 * <p>
 * Note that MongoDB doesn't support an {@code $nor} operator to be wrapped in a {@code $not} operator.
 *
 * @throws IllegalArgumentException if this method follows a {@link #not()} call directly.
 * @param criteria must not be {@literal null}.
 * @return this.
 * @since 3.2
 */
public Criteria orOperator(Collection<Criteria> criteria) {
    Assert.notNull(criteria, "Criteria must not be null!");
    BasicDBList bsonList = createCriteriaList(criteria);
    return registerCriteriaChainElement(new Criteria("$or").is(bsonList));
}
Also used : BasicDBList(com.mongodb.BasicDBList)

Example 87 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method readsCollectionOfDBRefs.

// DATAMONGO-424
@Test
void readsCollectionOfDBRefs() {
    DBRef dbRef = new DBRef("foo", 2);
    BasicDBList refs = new BasicDBList();
    refs.add(dbRef);
    org.bson.Document document = new org.bson.Document("refs", refs);
    DBRefWrapper result = converter.read(DBRefWrapper.class, document);
    assertThat(result.refs).hasSize(1);
    assertThat(result.refs).contains(dbRef);
}
Also used : BasicDBList(com.mongodb.BasicDBList) DBRef(com.mongodb.DBRef) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 88 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method readsListOfMapsCorrectly.

// DATAMONGO-259
@Test
void readsListOfMapsCorrectly() {
    org.bson.Document map = new org.bson.Document("Foo", "en");
    BasicDBList list = new BasicDBList();
    list.add(map);
    org.bson.Document wrapperSource = new org.bson.Document("listOfMaps", list);
    CollectionWrapper wrapper = converter.read(CollectionWrapper.class, wrapperSource);
    assertThat(wrapper.listOfMaps).isNotNull();
    assertThat(wrapper.listOfMaps.size()).isEqualTo(1);
    assertThat(wrapper.listOfMaps.get(0)).isNotNull();
    assertThat(wrapper.listOfMaps.get(0).get("Foo")).isEqualTo(Locale.ENGLISH);
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 89 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterUnitTests method readsMapListDoublyNestedValuesCorrectly.

// DATAMONGO-245
@Test
void readsMapListDoublyNestedValuesCorrectly() {
    BasicDBList list = new BasicDBList();
    org.bson.Document nested = new org.bson.Document();
    org.bson.Document doubly = new org.bson.Document();
    doubly.append("Hello", "World");
    nested.append("nested", doubly);
    list.add(nested);
    org.bson.Document source = new org.bson.Document("mapOfObjects", new org.bson.Document("Foo", list));
    ClassWithMapProperty result = converter.read(ClassWithMapProperty.class, source);
    Object firstObjectInFoo = ((List<?>) result.mapOfObjects.get("Foo")).get(0);
    assertThat(firstObjectInFoo).isInstanceOf(Map.class);
    Object doublyNestedObject = ((Map<?, ?>) firstObjectInFoo).get("nested");
    assertThat(doublyNestedObject).isInstanceOf(Map.class);
    assertThat(((Map<?, ?>) doublyNestedObject).get("Hello")).isEqualTo("World");
}
Also used : BasicDBList(com.mongodb.BasicDBList) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BasicDBList(com.mongodb.BasicDBList) Document(org.springframework.data.mongodb.core.mapping.Document) Test(org.junit.jupiter.api.Test)

Example 90 with BasicDBList

use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.

the class BsonUtilsTest method supportsBsonShouldReportIfConversionSupported.

// GH-3702
@Test
void supportsBsonShouldReportIfConversionSupported() {
    assertThat(BsonUtils.supportsBson("foo")).isFalse();
    assertThat(BsonUtils.supportsBson(new Document())).isTrue();
    assertThat(BsonUtils.supportsBson(new BasicDBList())).isTrue();
    assertThat(BsonUtils.supportsBson(Collections.emptyMap())).isTrue();
}
Also used : BasicDBList(com.mongodb.BasicDBList) Document(org.bson.Document) Test(org.junit.jupiter.api.Test)

Aggregations

BasicDBList (com.mongodb.BasicDBList)108 BasicDBObject (com.mongodb.BasicDBObject)69 DBObject (com.mongodb.DBObject)50 Test (org.junit.jupiter.api.Test)17 Document (org.springframework.data.mongodb.core.mapping.Document)14 DBCollection (com.mongodb.DBCollection)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 DBCursor (com.mongodb.DBCursor)8 DBRef (com.mongodb.DBRef)8 List (java.util.List)7 Document (org.bson.Document)7 HashMap (java.util.HashMap)6 ObjectId (org.bson.types.ObjectId)6 MongoClient (com.mongodb.MongoClient)4 Map (java.util.Map)4 NotFoundException (org.graylog2.database.NotFoundException)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 MongoInputSplit (com.mongodb.hadoop.input.MongoInputSplit)3 IOException (java.io.IOException)3