use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method doesNotTranslateNonIdPropertiesFor$NeCriteria.
// DATAMONGO-493
@Test
void doesNotTranslateNonIdPropertiesFor$NeCriteria() {
ObjectId accidentallyAnObjectId = new ObjectId();
Query query = Query.query(Criteria.where("id").is("id_value").and("publishers").ne(accidentallyAnObjectId.toString()));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(UserEntity.class));
assertThat(document.get("publishers")).isInstanceOf(org.bson.Document.class);
org.bson.Document publishers = (org.bson.Document) document.get("publishers");
assertThat(publishers).containsKey("$ne");
assertThat(publishers.get("$ne")).isInstanceOf(String.class);
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method mapsNullBsonTypeForFieldWithCustomTargetType.
// GH-3633
@Test
void mapsNullBsonTypeForFieldWithCustomTargetType() {
Query query = query(where("stringAsOid").isNullValue());
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(NonIdFieldWithObjectIdTargetType.class));
assertThat(document).isEqualTo(new org.bson.Document("stringAsOid", new org.bson.Document("$type", 10)));
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method getMappedSortIgnoresTextScoreWhenNotSortedByScore.
// DATAMONGO-973
@Test
void getMappedSortIgnoresTextScoreWhenNotSortedByScore() {
Query query = new Query().with(Sort.by("id"));
org.bson.Document document = mapper.getMappedSort(query.getSortObject(), context.getPersistentEntity(WithTextScoreProperty.class));
assertThat(document).isEqualTo(new org.bson.Document().append("_id", 1));
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method getMappedFieldsReplacesTextScoreFieldProperlyCorrectlyWhenPresent.
// DATAMONGO-973
@Test
void getMappedFieldsReplacesTextScoreFieldProperlyCorrectlyWhenPresent() {
Query query = new Query();
query.fields().include("textScore");
org.bson.Document document = mapper.getMappedFields(query.getFieldsObject(), context.getPersistentEntity(WithTextScoreProperty.class));
assertThat(document).isEqualTo(new org.bson.Document().append("score", new org.bson.Document("$meta", "textScore")));
}
use of org.springframework.data.mongodb.core.mapping.Document in project spring-data-mongodb by spring-projects.
the class QueryMapperUnitTests method shouldMapQueryForNestedCustomizedPropertiesUsingConfiguredFieldNames.
// DATAMONGO-1406
@Test
void shouldMapQueryForNestedCustomizedPropertiesUsingConfiguredFieldNames() {
EmbeddedClass embeddedClass = new EmbeddedClass();
embeddedClass.customizedField = "hello";
Foo foo = new Foo();
foo.listOfItems = Collections.singletonList(embeddedClass);
Query query = new Query(//
Criteria.where("listOfItems").elemMatch(//
new Criteria().andOperator(Criteria.where("customizedField").is(embeddedClass.customizedField))));
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), context.getPersistentEntity(Foo.class));
assertThat(document).containsEntry("my_items.$elemMatch.$and", Collections.singletonList(new org.bson.Document("fancy_custom_name", embeddedClass.customizedField)));
}
Aggregations