diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java index 1b932e951..be19f0e35 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2017 the original author or authors. + * Copyright 2011-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -592,7 +592,7 @@ public class QueryMapper { * @since 1.8 */ public boolean isSample() { - return "$sample".equalsIgnoreCase(key); + return "$example".equalsIgnoreCase(key); } public boolean hasIterableValue() { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index dd843e898..e67d6b589 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2017 the original author or authors. + * Copyright 2010-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -541,7 +541,7 @@ public class Criteria implements CriteriaDefinition { */ public Criteria alike(Example sample) { - criteria.put("$sample", sample); + criteria.put("$example", sample); this.criteriaChain.add(this); return this; } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java index 07353d7e1..787d9dc92 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/QueryMapperUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2017 the original author or authors. + * Copyright 2011-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; - import org.springframework.data.annotation.Id; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; @@ -140,6 +139,14 @@ public class QueryMapperUnitTests { assertThat(dbObject.get("$ne"), is(instanceOf(ObjectId.class))); } + @Test // DATAMONGO-2023 + public void translates$SampleCorrectly() { + + DBObject dbObject = new BasicDBObject("$sample", new BasicDBObject("size", 1)); + DBObject result = mapper.getMappedObject(dbObject, context.getPersistentEntity(Sample.class)); + assertThat((BasicDBObject) result.get("$sample"), is(new BasicDBObject("size", 1))); + } + @Test // DATAMONGO-326 public void handlesEnumsCorrectly() { Query query = query(where("foo").is(Enum.INSTANCE));