diff --git a/core/src/main/java/dev/morphia/mapping/codec/filters/NearFilterCodec.java b/core/src/main/java/dev/morphia/mapping/codec/filters/NearFilterCodec.java index 333b627a17f..d8001466b7a 100644 --- a/core/src/main/java/dev/morphia/mapping/codec/filters/NearFilterCodec.java +++ b/core/src/main/java/dev/morphia/mapping/codec/filters/NearFilterCodec.java @@ -33,8 +33,8 @@ private void encodeFilter(BsonWriter writer, NearFilter near, EncoderContext con document(writer, near.getName(), () -> { writer.writeName("$geometry"); CodecHelper.unnamedValue(writer, datastore, near.getValue(datastore), context); - value(writer, "$maxDistance", near.maxDistance()); value(writer, "$minDistance", near.minDistance()); + value(writer, "$maxDistance", near.maxDistance()); value(datastore.getCodecRegistry(), writer, "crs", near.crs(), context); }); } diff --git a/core/src/main/java/dev/morphia/query/FindOptions.java b/core/src/main/java/dev/morphia/query/FindOptions.java index fd674a521c9..04758bb2df4 100644 --- a/core/src/main/java/dev/morphia/query/FindOptions.java +++ b/core/src/main/java/dev/morphia/query/FindOptions.java @@ -41,6 +41,9 @@ public final class FindOptions implements ReadConfigurable, CollectionConfigurable { private Boolean allowDiskUse; private int batchSize; + + private boolean disableValidation = false; + private int limit; private long maxTimeMS; private long maxAwaitTimeMS; @@ -92,6 +95,7 @@ public FindIterable apply(FindIterable iterable, Mapper mapper, Class< logQuery(); // reset to a new ID } if (projection != null) { + projection.disableValidation(disableValidation); iterable.projection(projection.map(mapper, type)); } @@ -251,6 +255,16 @@ public FindOptions cursorType(CursorType cursorType) { return this; } + /** + * @param disable + * @hidden + * @morphia.internal + */ + @MorphiaInternal + public void disableValidation(boolean disable) { + this.disableValidation = disable; + } + /** * @hidden * @morphia.internal diff --git a/core/src/main/java/dev/morphia/query/MorphiaQuery.java b/core/src/main/java/dev/morphia/query/MorphiaQuery.java index aaca5beff3e..0b2812141cf 100644 --- a/core/src/main/java/dev/morphia/query/MorphiaQuery.java +++ b/core/src/main/java/dev/morphia/query/MorphiaQuery.java @@ -206,8 +206,8 @@ public boolean isValidate() { } @Override - public MorphiaCursor iterator(FindOptions options) { - return new MorphiaCursor<>(prepareCursor(options, collection)); + public MorphiaCursor iterator(@Nullable FindOptions options) { + return new MorphiaCursor<>(prepareCursor(options != null ? options : new FindOptions(), collection)); } /** @@ -317,6 +317,7 @@ private MongoCursor prepareCursor(FindOptions options, MongoCollection if (options.isLogQuery()) { oldProfile = datastore.getDatabase().runCommand(new Document("profile", 2).append("slowms", 0)); } + options.disableValidation(!isValidate()); try { return options .apply(iterable(options, collection), mapper, type) diff --git a/core/src/main/java/dev/morphia/query/Projection.java b/core/src/main/java/dev/morphia/query/Projection.java index 710227a5e69..681ee560942 100644 --- a/core/src/main/java/dev/morphia/query/Projection.java +++ b/core/src/main/java/dev/morphia/query/Projection.java @@ -7,9 +7,9 @@ import com.mongodb.lang.Nullable; import dev.morphia.annotations.Entity; +import dev.morphia.annotations.internal.MorphiaInternal; import dev.morphia.internal.PathTarget; import dev.morphia.mapping.Mapper; -import dev.morphia.mapping.codec.pojo.EntityModel; import dev.morphia.sofia.Sofia; import org.bson.Document; @@ -19,6 +19,9 @@ */ public class Projection { private final FindOptions options; + + private boolean disableValidation; + private List includes; private List excludes; private String arrayField; @@ -30,6 +33,17 @@ public class Projection { this.options = options; } + /** + * @param disableValidation + * @hidden + * @morphia.internal + */ + @MorphiaInternal + public void disableValidation(boolean disableValidation) { + + this.disableValidation = disableValidation; + } + /** * Adds a field to the projection clause. The _id field is always included unless explicitly suppressed. * @@ -112,7 +126,8 @@ private void iterate(Mapper mapper, Document projection, Class clazz, @Nullab int include) { if (fields != null) { for (String field : fields) { - projection.put(new PathTarget(mapper, mapper.getEntityModel(clazz), field).translatedPath(), include); + String key = disableValidation ? field : new PathTarget(mapper, mapper.getEntityModel(clazz), field).translatedPath(); + projection.put(key, include); } } } @@ -137,8 +152,10 @@ private Document project(Mapper mapper, Class clazz) { iterate(mapper, projection, clazz, includes, 1); iterate(mapper, projection, clazz, excludes, 0); - final EntityModel model = mapper.getEntityModel(clazz); - Entity entityAnnotation = model.getEntityAnnotation(); + Entity entityAnnotation = null; + if (!clazz.equals(Document.class)) { + entityAnnotation = mapper.getEntityModel(clazz).getEntityAnnotation(); + } if (isIncluding() && entityAnnotation != null && entityAnnotation.useDiscriminator()) { projection.put(mapper.getConfig().discriminatorKey(), 1); @@ -148,7 +165,9 @@ private Document project(Mapper mapper, Class clazz) { } private Document slice(Mapper mapper, Class clazz) { - String fieldName = new PathTarget(mapper, mapper.getEntityModel(clazz), arrayField).translatedPath(); + String fieldName = disableValidation + ? arrayField + : new PathTarget(mapper, mapper.getEntityModel(clazz), arrayField).translatedPath(); return new Document(fieldName, slice.toDatabase()); } diff --git a/core/src/main/java/dev/morphia/query/Query.java b/core/src/main/java/dev/morphia/query/Query.java index befe9a9e182..4c2405599c6 100644 --- a/core/src/main/java/dev/morphia/query/Query.java +++ b/core/src/main/java/dev/morphia/query/Query.java @@ -206,7 +206,7 @@ default T modify(ModifyOptions options, UpdateOperator first, UpdateOperator... * @return a MorphiaCursor * @since 2.0 */ - MorphiaCursor iterator(FindOptions options); + MorphiaCursor iterator(@Nullable FindOptions options); /** * Provides a {@link Stream} representation of the results of this query. diff --git a/core/src/main/java/dev/morphia/query/filters/Filters.java b/core/src/main/java/dev/morphia/query/filters/Filters.java index 5aa421e2420..df684e77db8 100644 --- a/core/src/main/java/dev/morphia/query/filters/Filters.java +++ b/core/src/main/java/dev/morphia/query/filters/Filters.java @@ -395,6 +395,20 @@ public static Filter mod(String field, long divisor, long remainder) { return new ModFilter(field, divisor, remainder); } + /** + * Performs a modulo operation on the value of a field and selects documents with a specified result. + * + * @param field the field to check + * @param divisor the value to divide by + * @param remainder the remainder to check for + * @return the filter + * @query.filter $mod + * @since 3.0 + */ + public static Filter mod(String field, double divisor, double remainder) { + return new ModFilter(field, divisor, remainder); + } + /** * $ne selects the documents where the value of the field is not equal to the specified value. This includes documents that do not * contain the field. diff --git a/core/src/main/java/dev/morphia/query/filters/ModFilter.java b/core/src/main/java/dev/morphia/query/filters/ModFilter.java index 8cd60622244..1931969a426 100644 --- a/core/src/main/java/dev/morphia/query/filters/ModFilter.java +++ b/core/src/main/java/dev/morphia/query/filters/ModFilter.java @@ -8,11 +8,11 @@ */ @MorphiaInternal public class ModFilter extends Filter { - private final long divisor; + private final Number divisor; - private final long remainder; + private final Number remainder; - public ModFilter(String field, long divisor, long remainder) { + public ModFilter(String field, Number divisor, Number remainder) { super("$mod", field, null); this.divisor = divisor; this.remainder = remainder; @@ -24,7 +24,7 @@ public ModFilter(String field, long divisor, long remainder) { * @return the divisor */ @MorphiaInternal - public long divisor() { + public Number divisor() { return divisor; } @@ -34,7 +34,7 @@ public long divisor() { * @return the remainder */ @MorphiaInternal - public long remainder() { + public Number remainder() { return remainder; } } diff --git a/core/src/test/java/dev/morphia/test/query/FiltersTest.java b/core/src/test/java/dev/morphia/test/query/FiltersTest.java index 2ce5ddee8e6..201c4e56937 100644 --- a/core/src/test/java/dev/morphia/test/query/FiltersTest.java +++ b/core/src/test/java/dev/morphia/test/query/FiltersTest.java @@ -14,11 +14,9 @@ import dev.morphia.annotations.Id; import dev.morphia.query.FindOptions; import dev.morphia.query.Meta; -import dev.morphia.query.MorphiaQuery; import dev.morphia.query.Query; import dev.morphia.query.Type; import dev.morphia.test.TemplatedTestBase; -import dev.morphia.test.aggregation.model.Inventory; import dev.morphia.test.models.Budget; import dev.morphia.test.models.User; @@ -30,19 +28,10 @@ import static dev.morphia.aggregation.expressions.Miscellaneous.rand; import static dev.morphia.aggregation.expressions.Miscellaneous.sampleRate; import static dev.morphia.aggregation.stages.Match.match; -import static dev.morphia.query.filters.Filters.and; -import static dev.morphia.query.filters.Filters.bitsAllClear; -import static dev.morphia.query.filters.Filters.bitsAllSet; -import static dev.morphia.query.filters.Filters.bitsAnyClear; -import static dev.morphia.query.filters.Filters.bitsAnySet; import static dev.morphia.query.filters.Filters.expr; import static dev.morphia.query.filters.Filters.gt; -import static dev.morphia.query.filters.Filters.gte; -import static dev.morphia.query.filters.Filters.in; import static dev.morphia.query.filters.Filters.jsonSchema; import static dev.morphia.query.filters.Filters.lt; -import static dev.morphia.query.filters.Filters.lte; -import static dev.morphia.query.filters.Filters.mod; import static dev.morphia.query.filters.Filters.nin; import static dev.morphia.query.filters.Filters.nor; import static dev.morphia.query.filters.Filters.or; @@ -65,16 +54,6 @@ public class FiltersTest extends TemplatedTestBase { public void testCoverage() { } - @Test - public void testAnd() { - getDs().find(Budget.class) - .filter(and(lt("budget", 10000), gt("budget", 12))) - .iterator(); - getDs().find(Budget.class) - .filter(and(lte("budget", 10000), gte("budget", 12))) - .iterator(); - } - @Test public void testType() { User entity = new User(); @@ -88,100 +67,6 @@ public void testType() { Assert.assertTrue(query.count() > 0); } - @Test - public void testBitsAllClear() { - MongoCollection collection = getDatabase().getCollection("users"); - - String discriminator = User.class.getName(); - collection.insertMany(asList( - new Document("a", 54).append("binaryValueofA", "00110110").append("_t", discriminator), - new Document("a", 20).append("binaryValueofA", "00010100").append("_t", discriminator), - new Document("a", 20.0).append("binaryValueofA", "00010100").append("_t", discriminator))); - - FindOptions options = new FindOptions().logQuery(); - - Query query = getDs().find(User.class) - .disableValidation() - .filter(bitsAllClear("a", 35)); - assertEquals(query.iterator(options).toList().size(), 2, query.getLoggedQuery()); - - query = getDs().find(User.class) - .disableValidation() - .filter(bitsAllClear("a", new int[] { 1, 5 })); - assertEquals(query.iterator(options).toList().size(), 2, query.getLoggedQuery()); - } - - @Test - public void testBitsAllSet() { - MongoCollection collection = getDatabase().getCollection("users"); - - String discriminator = User.class.getName(); - collection.insertMany(asList( - new Document("a", 54).append("binaryValueofA", "00110110").append("_t", discriminator), - new Document("a", 20).append("binaryValueofA", "00010100").append("_t", discriminator), - new Document("a", 20.0).append("binaryValueofA", "00010100").append("_t", discriminator))); - - final FindOptions options = new FindOptions().logQuery(); - - Query query = getDs().find(User.class) - .disableValidation() - .filter(bitsAllSet("a", 50)); - assertEquals(query.iterator(options).toList().size(), 1, query.getLoggedQuery()); - - query = getDs().find(User.class) - .disableValidation() - .filter(bitsAllSet("a", new int[] { 1, 5 })); - assertEquals(query.iterator(options) - .toList().size(), 1, query.getLoggedQuery()); - } - - @Test - public void testBitsAnyClear() { - MongoCollection collection = getDatabase().getCollection("users"); - - String discriminator = User.class.getName(); - collection.insertMany(asList( - new Document("a", 54).append("binaryValueofA", "00110110").append("_t", discriminator), - new Document("a", 20).append("binaryValueofA", "00010100").append("_t", discriminator), - new Document("a", 20.0).append("binaryValueofA", "00010100").append("_t", discriminator))); - - FindOptions options = new FindOptions().logQuery(); - - Query query = getDs().find(User.class) - .disableValidation() - .filter(bitsAnyClear("a", 35)); - assertEquals(query.iterator(options).toList().size(), 3, query.getLoggedQuery()); - - query = getDs().find(User.class) - .disableValidation() - .filter(bitsAnyClear("a", new int[] { 1, 5 })); - assertEquals(query.iterator(options) - .toList().size(), 2, query.getLoggedQuery()); - } - - @Test - public void testBitsAnySet() { - MongoCollection collection = getDatabase().getCollection("users"); - - String discriminator = User.class.getName(); - collection.insertMany(asList( - new Document("a", 54).append("binaryValueofA", "00110110").append("_t", discriminator), - new Document("a", 20).append("binaryValueofA", "00010100").append("_t", discriminator), - new Document("a", 20.0).append("binaryValueofA", "00010100").append("_t", discriminator))); - - FindOptions options = new FindOptions().logQuery(); - - Query query = getDs().find(User.class) - .disableValidation() - .filter(bitsAnySet("a", 35)); - assertEquals(query.iterator(options).toList().size(), 1, query.getLoggedQuery()); - - assertEquals(getDs().find(User.class) - .disableValidation() - .filter(bitsAnySet("a", new int[] { 1, 5 })).iterator(options) - .toList().size(), 1, query.getLoggedQuery()); - } - @Test public void testExpr() { insert("budget", asList( @@ -198,13 +83,6 @@ public void testExpr() { assertEquals(budgets.size(), 3); } - @Test - public void testIn() { - getDs().find(Budget.class) - .filter(in("budget", asList(123, 234))) - .iterator(); - } - @Test public void testJsonSchema() { insert("inventory", List.of( @@ -270,15 +148,6 @@ public void testMeta() { } - @Test - public void testMod() { - var query = getDs().find(Inventory.class) - .disableValidation() - .filter(mod("qty", 4, 0)); - testQuery((MorphiaQuery) query, new FindOptions(), true); - - } - @Test public void testNin() { getDs().find(Budget.class) diff --git a/core/src/test/java/dev/morphia/test/query/filters/FilterTest.java b/core/src/test/java/dev/morphia/test/query/filters/FilterTest.java index 335085e4a70..6197560b61f 100644 --- a/core/src/test/java/dev/morphia/test/query/filters/FilterTest.java +++ b/core/src/test/java/dev/morphia/test/query/filters/FilterTest.java @@ -4,6 +4,7 @@ import java.util.List; import java.util.function.Function; +import dev.morphia.query.FindOptions; import dev.morphia.query.MorphiaQuery; import dev.morphia.query.Query; import dev.morphia.test.TemplatedTestBase; @@ -37,15 +38,17 @@ public void testQuery(QueryTestOptions options, Function, Query> function) { checkMinServerVersion(options.serverVersion()); - checkMinDriverVersion(minDriver); + checkMinDriverVersion(options.minDriver()); var resourceName = discoverResourceName(); validateTestName(resourceName); - if (!options.skipDataCheck()) + if (!options.skipDataCheck()) { loadData(resourceName, AGG_TEST_COLLECTION); + } loadIndex(resourceName, AGG_TEST_COLLECTION); - List actual = runQuery(resourceName, function.apply(getDs().find(AGG_TEST_COLLECTION, Document.class) - .disableValidation())); + Query apply = function.apply(getDs().find(AGG_TEST_COLLECTION, Document.class) + .disableValidation()); + List actual = runQuery(resourceName, apply, options.findOptions()); if (!options.skipDataCheck()) { List expected = loadExpected(resourceName); @@ -72,7 +75,7 @@ private void validateTestName(String resourceName) { } @SuppressWarnings({ "unchecked", "rawtypes" }) - protected List runQuery(String pipelineTemplate, Query query) { + protected List runQuery(String pipelineTemplate, Query query, FindOptions options) { String resourceName = format("%s/%s/action.json", prefix(), pipelineTemplate); Document document = ((MorphiaQuery) query).toDocument(); @@ -82,7 +85,7 @@ protected List runQuery(String pipelineTemplate, Query query } if (!skipDataCheck) { - try (var cursor = query.iterator()) { + try (var cursor = query.iterator(options)) { return cursor.toList(); } } else { diff --git a/core/src/test/java/dev/morphia/test/query/filters/QueryTestOptions.java b/core/src/test/java/dev/morphia/test/query/filters/QueryTestOptions.java index 38692f6997f..3024e07c365 100644 --- a/core/src/test/java/dev/morphia/test/query/filters/QueryTestOptions.java +++ b/core/src/test/java/dev/morphia/test/query/filters/QueryTestOptions.java @@ -1,10 +1,16 @@ package dev.morphia.test.query.filters; +import dev.morphia.query.FindOptions; +import dev.morphia.test.DriverVersion; import dev.morphia.test.ServerVersion; import static dev.morphia.test.ServerVersion.ANY; public class QueryTestOptions { + private FindOptions findOptions; + + private DriverVersion minDriver = DriverVersion.v41; + private boolean orderMatters = true; private boolean removeIds = false; @@ -17,6 +23,24 @@ public QueryTestOptions() { serverVersion = ANY; } + public FindOptions findOptions() { + return findOptions; + } + + public QueryTestOptions findOptions(FindOptions findOptions) { + this.findOptions = findOptions; + return this; + } + + public DriverVersion minDriver() { + return minDriver; + } + + public QueryTestOptions minDriver(DriverVersion minDriver) { + this.minDriver = minDriver; + return this; + } + public boolean orderMatters() { return orderMatters; } diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestCenter.java b/core/src/test/java/dev/morphia/test/query/filters/TestCenter.java new file mode 100644 index 00000000000..fa02d6c7be6 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestCenter.java @@ -0,0 +1,21 @@ +package dev.morphia.test.query.filters; + +import com.mongodb.client.model.geojson.Point; +import com.mongodb.client.model.geojson.Position; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.center; + +public class TestCenter extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/center/example1 + */ + @Test(testName = "main") + public void testExample1() { + testQuery(new QueryTestOptions().skipDataCheck(true), + (query) -> query.filter( + center("loc", new Point(new Position(-74, 40.74)), 10))); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestExists.java b/core/src/test/java/dev/morphia/test/query/filters/TestExists.java new file mode 100644 index 00000000000..cc88f3ad6ee --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestExists.java @@ -0,0 +1,32 @@ +package dev.morphia.test.query.filters; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.exists; + +public class TestExists extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/exists/example1 + */ + @Test(testName = "Exists and Not Equal To") + public void testExample1() { + testQuery(new QueryTestOptions().removeIds(true), + (query) -> query.filter( + exists("saffron"))); + } + + /** + * test data: dev/morphia/test/query/filters/exists/example2 + * + * db.spices.find( { saffron: { $exists: true } } ) + */ + @Test(testName = "Null Values") + public void testExample2() { + testQuery(new QueryTestOptions().removeIds(true), + (query) -> query.filter( + exists("cinnamon").not() + + )); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestExpr.java b/core/src/test/java/dev/morphia/test/query/filters/TestExpr.java new file mode 100644 index 00000000000..67ebd29f601 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestExpr.java @@ -0,0 +1,31 @@ +package dev.morphia.test.query.filters; + +import org.testng.annotations.Test; + +import static dev.morphia.aggregation.expressions.ComparisonExpressions.gt; +import static dev.morphia.aggregation.expressions.ComparisonExpressions.gte; +import static dev.morphia.aggregation.expressions.ComparisonExpressions.lt; +import static dev.morphia.aggregation.expressions.ConditionalExpressions.condition; +import static dev.morphia.aggregation.expressions.MathExpressions.multiply; +import static dev.morphia.query.filters.Filters.expr; + +public class TestExpr extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/expr/example1 + */ + @Test(testName = "Compare Two Fields from A Single Document") + public void testExample1() { + testQuery((query) -> query.filter( + expr(gt("$spent", "$budget")))); + } + + /** + * test data: dev/morphia/test/query/filters/expr/example2 + */ + @Test(testName = "Using ``$expr`` With Conditional Statements", enabled = false, description = "parsing bug in Document's json parsing at $cond") + public void testExample2() { + testQuery((query) -> query.filter( + expr(lt(condition(gte("qty", 100), multiply("$price", 0.5), multiply("$price", 0.75)), 5.0)))); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestGte.java b/core/src/test/java/dev/morphia/test/query/filters/TestGte.java new file mode 100644 index 00000000000..e4b6f1f836c --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestGte.java @@ -0,0 +1,20 @@ +package dev.morphia.test.query.filters; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.gte; + +public class TestGte extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/gte/example1 + * + * db.inventory.find( { quantity: { $gte: 20 } } ) + */ + @Test(testName = "Match Document Fields") + public void testExample1() { + testQuery(new QueryTestOptions().removeIds(true), + (query) -> query.filter( + gte("quantity", 20))); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestIn.java b/core/src/test/java/dev/morphia/test/query/filters/TestIn.java new file mode 100644 index 00000000000..e16b2bb8e14 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestIn.java @@ -0,0 +1,35 @@ +package dev.morphia.test.query.filters; + +import java.util.List; +import java.util.regex.Pattern; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.in; + +public class TestIn extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/in/example1 + * + * db.inventory.find( { quantity: { $in: [ 5, 15 ] } }, { _id: 0 } ) + */ + @Test(testName = "Use the ``$in`` Operator to Match Values") + public void testExample1() { + testQuery(new QueryTestOptions().removeIds(true), + (query) -> query.filter( + in("quantity", List.of(5, 15)))); + } + + /** + * test data: dev/morphia/test/query/filters/in/example2 + * + * db.inventory.find( { tags: { $in: [ /^be/, /^st/ ] } } ) + */ + @Test(testName = "Use the ``$in`` Operator with a Regular Expression") + public void testExample2() { + testQuery(new QueryTestOptions().skipDataCheck(true), + (query) -> query.filter( + in("tags", List.of(Pattern.compile("^be"), Pattern.compile("^st"))))); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestLt.java b/core/src/test/java/dev/morphia/test/query/filters/TestLt.java new file mode 100644 index 00000000000..596a5745c64 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestLt.java @@ -0,0 +1,18 @@ +package dev.morphia.test.query.filters; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.lt; + +public class TestLt extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/lt/example1 + */ + @Test(testName = "Match Document Fields") + public void testExample1() { + testQuery(new QueryTestOptions().removeIds(true), + (query) -> query.filter( + lt("quantity", 20))); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestLte.java b/core/src/test/java/dev/morphia/test/query/filters/TestLte.java new file mode 100644 index 00000000000..c8e68238da0 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestLte.java @@ -0,0 +1,20 @@ +package dev.morphia.test.query.filters; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.lte; + +public class TestLte extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/lte/example1 + * + * db.inventory.find( { quantity: { $lte: 20 } } ) + */ + @Test(testName = "Match Document Fields") + public void testExample1() { + testQuery(new QueryTestOptions().removeIds(true), + (query) -> query.filter( + lte("quantity", 20))); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestMod.java b/core/src/test/java/dev/morphia/test/query/filters/TestMod.java new file mode 100644 index 00000000000..a26948e28ee --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestMod.java @@ -0,0 +1,59 @@ +package dev.morphia.test.query.filters; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.mod; + +public class TestMod extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/mod/example1 + * + * db.inventory.find( { qty: { $mod: [ 4, 0 ] } } ) + */ + @Test(testName = "Use ``$mod`` to Select Documents") + public void testExample1() { + testQuery((query) -> query.filter( + mod("qty", 4, 0))); + } + + /** + * test data: dev/morphia/test/query/filters/mod/example2 + * + * db.inventory.find( { qty: { $mod: [ 4 ] } } ) + */ + @Test(testName = "Not Enough Elements Error") + public void testExample2() { + // ignored + } + + /** + * test data: dev/morphia/test/query/filters/mod/example3 + */ + @Test(testName = "Too Many Elements Error") + public void testExample3() { + // ignored + } + + /** + * test data: dev/morphia/test/query/filters/mod/example4 + */ + @Test(testName = "Floating Point Arguments") + public void testExample4() { + testQuery((query) -> query.filter( + mod("qty", 4.0, 0.0) + + )); + } + + /** + * test data: dev/morphia/test/query/filters/mod/example5 + */ + @Test(testName = "Negative Dividend") + public void testExample5() { + testQuery((query) -> query.filter( + mod("qty", -4, -0) + + )); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestNear.java b/core/src/test/java/dev/morphia/test/query/filters/TestNear.java new file mode 100644 index 00000000000..8d1908aa40d --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestNear.java @@ -0,0 +1,38 @@ +package dev.morphia.test.query.filters; + +import com.mongodb.client.model.geojson.Point; +import com.mongodb.client.model.geojson.Position; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.near; + +public class TestNear extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/near/example1 + */ + @Test(testName = "Query on GeoJSON Data") + public void testExample1() { + testQuery(new QueryTestOptions().skipDataCheck(true), + (query) -> query.filter( + near("location", new Point(new Position(-73.9667, 40.78))) + .minDistance(1000.0) + .maxDistance(5000.0))); + } + + /** + * test data: dev/morphia/test/query/filters/near/example2 + */ + @Test(testName = "Query on Legacy Coordinates") + public void testExample2() { + // legacy coordinates just won't be supported for now + /* + * testQuery(new QueryTestOptions().skipDataCheck(true), + * (query) -> query.filter( + * near("location", new Point(new Position(-73.9667, 40.78))) + * .maxDistance(0.1) + * )); + */ + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestNin.java b/core/src/test/java/dev/morphia/test/query/filters/TestNin.java new file mode 100644 index 00000000000..372c00b1cb6 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestNin.java @@ -0,0 +1,22 @@ +package dev.morphia.test.query.filters; + +import java.util.List; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.nin; + +public class TestNin extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/nin/example1 + * + * db.inventory.find( { quantity: { $nin: [ 5, 15 ] } }, { _id: 0 } ) + */ + @Test(testName = "Select on Unmatching Documents") + public void testExample1() { + testQuery(new QueryTestOptions().removeIds(true), + (query) -> query.filter( + nin("quantity", List.of(5, 15)))); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestNor.java b/core/src/test/java/dev/morphia/test/query/filters/TestNor.java new file mode 100644 index 00000000000..69af77c71b3 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestNor.java @@ -0,0 +1,43 @@ +package dev.morphia.test.query.filters; + +import org.testng.annotations.Test; + +import static dev.morphia.query.filters.Filters.eq; +import static dev.morphia.query.filters.Filters.exists; +import static dev.morphia.query.filters.Filters.lt; +import static dev.morphia.query.filters.Filters.nor; + +public class TestNor extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/nor/example1 + */ + @Test(testName = "``$nor`` Query with Two Expressions") + public void testExample1() { + testQuery(new QueryTestOptions().skipDataCheck(true), + (query) -> query.filter( + nor(eq("price", 1.99), eq("sale", true)))); + } + + /** + * test data: dev/morphia/test/query/filters/nor/example2 + */ + @Test(testName = "``$nor`` and Additional Comparisons") + public void testExample2() { + testQuery(new QueryTestOptions().skipDataCheck(true), + (query) -> query.filter( + nor(eq("price", 1.99), lt("qty", 20), eq("sale", true)))); + } + + /** + * test data: dev/morphia/test/query/filters/nor/example3 + */ + @Test(testName = "``$nor`` and ``$exists``") + public void testExample3() { + testQuery(new QueryTestOptions().skipDataCheck(true), + (query) -> query.filter( + nor(eq("price", 1.99), exists("price").not(), eq("sale", true), exists("sale").not()) + + )); + } +} \ No newline at end of file diff --git a/core/src/test/java/dev/morphia/test/query/filters/TestRand.java b/core/src/test/java/dev/morphia/test/query/filters/TestRand.java new file mode 100644 index 00000000000..22ce583ec15 --- /dev/null +++ b/core/src/test/java/dev/morphia/test/query/filters/TestRand.java @@ -0,0 +1,31 @@ +package dev.morphia.test.query.filters; + +import dev.morphia.query.FindOptions; + +import org.testng.annotations.Test; + +import static dev.morphia.aggregation.expressions.ComparisonExpressions.lt; +import static dev.morphia.aggregation.expressions.Miscellaneous.rand; +import static dev.morphia.query.filters.Filters.eq; +import static dev.morphia.query.filters.Filters.expr; + +public class TestRand extends FilterTest { + + /** + * test data: dev/morphia/test/query/filters/rand/example1 + */ + @Test(testName = "Select Random Items From a Collection") + public void testExample1() { + QueryTestOptions options = new QueryTestOptions() + .orderMatters(false) + .removeIds(true) + .skipDataCheck(true) + .findOptions(new FindOptions() + .projection() + .include("name", "registered")); + testQuery(options, + (query) -> query.filter( + eq("district", 3), + expr(lt(0.5, rand())))); + } +} \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/center/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/center/example1/action.json new file mode 100644 index 00000000000..81722197d62 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/center/example1/action.json @@ -0,0 +1,3 @@ +db.places.find( + { loc: { $geoWithin: { $center: [ [-74.0, 40.74], 10.0 ] } } } +) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/center/example1/lock b/core/src/test/resources/dev/morphia/test/query/filters/center/example1/lock new file mode 100644 index 00000000000..0e9ec60ef85 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/center/example1/lock @@ -0,0 +1 @@ +converted the point values to doubles \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/center/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/center/example1/name new file mode 100644 index 00000000000..88d050b1908 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/center/example1/name @@ -0,0 +1 @@ +main \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/action.json new file mode 100644 index 00000000000..d70eafd0a54 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { saffron: { $exists: true } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/data.json new file mode 100644 index 00000000000..4082a1ddc8f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/data.json @@ -0,0 +1,10 @@ +{ saffron: 5, cinnamon: 5, mustard: null }, +{ saffron: 3, cinnamon: null, mustard: 8 }, +{ saffron: null, cinnamon: 3, mustard: 9 }, +{ saffron: 1, cinnamon: 2, mustard: 3 }, +{ saffron: 2, mustard: 5 }, +{ saffron: 3, cinnamon: 2 }, +{ saffron: 4 }, +{ cinnamon: 2, mustard: 4 }, +{ cinnamon: 2 }, +{ mustard: 6 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/expected.json new file mode 100644 index 00000000000..d80d9eeb3f8 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/expected.json @@ -0,0 +1,7 @@ +{ saffron: 5, cinnamon: 5, mustard: null } +{ saffron: 3, cinnamon: null, mustard: 8 } +{ saffron: null, cinnamon: 3, mustard: 9 } +{ saffron: 1, cinnamon: 2, mustard: 3 } +{ saffron: 2, mustard: 5 } +{ saffron: 3, cinnamon: 2 } +{ saffron: 4 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/lock b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/lock new file mode 100644 index 00000000000..a6ded86c830 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/lock @@ -0,0 +1 @@ +this example is convoluted so i had to manually collect the inputs \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/name new file mode 100644 index 00000000000..f4c2958729d --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example1/name @@ -0,0 +1 @@ +Exists and Not Equal To \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/action.json b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/action.json new file mode 100644 index 00000000000..0c61b371b27 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/action.json @@ -0,0 +1 @@ +db.spices.find( { cinnamon: { $exists: false } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/data.json b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/data.json new file mode 100644 index 00000000000..4082a1ddc8f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/data.json @@ -0,0 +1,10 @@ +{ saffron: 5, cinnamon: 5, mustard: null }, +{ saffron: 3, cinnamon: null, mustard: 8 }, +{ saffron: null, cinnamon: 3, mustard: 9 }, +{ saffron: 1, cinnamon: 2, mustard: 3 }, +{ saffron: 2, mustard: 5 }, +{ saffron: 3, cinnamon: 2 }, +{ saffron: 4 }, +{ cinnamon: 2, mustard: 4 }, +{ cinnamon: 2 }, +{ mustard: 6 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/expected.json new file mode 100644 index 00000000000..b8b029a714f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/expected.json @@ -0,0 +1,3 @@ +{ saffron: 2, mustard: 5 } +{ saffron: 4 } +{ mustard: 6 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/lock b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/lock new file mode 100644 index 00000000000..a6ded86c830 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/lock @@ -0,0 +1 @@ +this example is convoluted so i had to manually collect the inputs \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/name b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/name new file mode 100644 index 00000000000..dfafb01e169 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/exists/example2/name @@ -0,0 +1 @@ +Null Values \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/action.json new file mode 100644 index 00000000000..70ae9256736 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/action.json @@ -0,0 +1 @@ +db.monthlyBudget.find( { $expr: { $gt: [ "$spent" , "$budget" ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/data.json new file mode 100644 index 00000000000..04f7556fd3a --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/data.json @@ -0,0 +1,5 @@ +{ _id : 1, category : "food", budget : 400, spent : 450 }, +{ _id : 2, category : "drinks", budget : 100, spent : 150 }, +{ _id : 3, category : "clothes", budget : 100, spent : 50 }, +{ _id : 4, category : "misc", budget : 500, spent : 300 }, +{ _id : 5, category : "travel", budget : 200, spent : 650 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/expected.json new file mode 100644 index 00000000000..945d517b8e7 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/expected.json @@ -0,0 +1,3 @@ +{ _id : 1, category : "food", budget : 400, spent : 450 } +{ _id : 2, category : "drinks", budget : 100, spent : 150 } +{ _id : 5, category : "travel", budget : 200, spent : 650 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/lock b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/lock new file mode 100644 index 00000000000..c3765d343ed --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/lock @@ -0,0 +1 @@ +wrapped the variable refs in quotes \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/name new file mode 100644 index 00000000000..4252ff682de --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example1/name @@ -0,0 +1 @@ +Compare Two Fields from A Single Document \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/action.json b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/action.json new file mode 100644 index 00000000000..785932a8ee2 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/action.json @@ -0,0 +1,6 @@ +db.supplies.find( { $expr: { $lt: [ + $cond: [ + { $gte: ["$qty", 100] }, + { $multiply: ["$price", 0.50] }, + { $multiply: ["$price", 0.75] } + ] , 5 ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/data.json b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/data.json new file mode 100644 index 00000000000..3c4cb8c7b47 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/data.json @@ -0,0 +1,5 @@ +{ _id : 1, item : "binder", qty : NumberInt("100"), price : NumberDecimal("12") }, +{ _id : 2, item : "notebook", qty : NumberInt("200"), price : NumberDecimal("8") }, +{ _id : 3, item : "pencil", qty : NumberInt("50"), price : NumberDecimal("6") }, +{ _id : 4, item : "eraser", qty : NumberInt("150"), price : NumberDecimal("3") }, +{ _id : 5, item : "legal pad", qty : NumberInt("42"), price : NumberDecimal("10") } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/expected.json new file mode 100644 index 00000000000..5cbb54c183c --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/expected.json @@ -0,0 +1,3 @@ +{ _id : 2, item : "notebook", qty : 200 , price : NumberDecimal("8") } +{ _id : 3, item : "pencil", qty : 50 , price : NumberDecimal("6") } +{ _id : 4, item : "eraser", qty : 150 , price : NumberDecimal("3") } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/name b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/name new file mode 100644 index 00000000000..becd7bb62da --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/expr/example2/name @@ -0,0 +1 @@ +Using ``$expr`` With Conditional Statements \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/action.json new file mode 100644 index 00000000000..c4496fc1665 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { quantity: { $gte: 20 } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/data.json new file mode 100644 index 00000000000..c1d2781b7de --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/data.json @@ -0,0 +1,3 @@ +{ "item": "nuts", "quantity": 30, "carrier": { "name": "Shipit", "fee": 3 } }, +{ "item": "bolts", "quantity": 50, "carrier": { "name": "Shipit", "fee": 4 } }, +{ "item": "washers", "quantity": 10, "carrier": { "name": "Shipit", "fee": 1 } } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/expected.json new file mode 100644 index 00000000000..e4badf9959f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/expected.json @@ -0,0 +1,2 @@ +{ _id: ObjectId("61bb51211b83c864e3bbe037"), item: 'nuts', quantity: 30, carrier: { name: 'Shipit', fee: 3 }}, +{ _id: ObjectId("61bb51211b83c864e3bbe038"), item: 'bolts', quantity: 50, carrier: { name: 'Shipit', fee: 4 }} \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/lock b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/lock new file mode 100644 index 00000000000..97fccb2fa08 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/lock @@ -0,0 +1 @@ +missing a closing brace \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/name new file mode 100644 index 00000000000..f19ec4ead4e --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/gte/example1/name @@ -0,0 +1 @@ +Match Document Fields \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/in/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/action.json new file mode 100644 index 00000000000..a1e99ecb675 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { quantity: { $in: [ 5, 15 ] } }, { _id: 0 } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/in/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/data.json new file mode 100644 index 00000000000..24cc1e141ff --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/data.json @@ -0,0 +1,4 @@ +{ "item": "Pens", "quantity": 350, "tags": [ "school", "office" ] }, +{ "item": "Erasers", "quantity": 15, "tags": [ "school", "home" ] }, +{ "item": "Maps", "tags": [ "office", "storage" ] }, +{ "item": "Books", "quantity": 5, "tags": [ "school", "storage", "home" ] } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/in/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/expected.json new file mode 100644 index 00000000000..0a40e67d2be --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/expected.json @@ -0,0 +1,2 @@ +{ item: 'Erasers', quantity: 15, tags: [ 'school', 'home' ] }, +{ item: 'Books', quantity: 5, tags: [ 'school', 'storage', 'home' ] } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/in/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/name new file mode 100644 index 00000000000..ad07067a10b --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/in/example1/name @@ -0,0 +1 @@ +Use the ``$in`` Operator to Match Values \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/in/example2/action.json b/core/src/test/resources/dev/morphia/test/query/filters/in/example2/action.json new file mode 100644 index 00000000000..cd0f68a5d2e --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/in/example2/action.json @@ -0,0 +1 @@ +db.inventory.find( { tags: { $in: [ /^be/, /^st/ ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/in/example2/name b/core/src/test/resources/dev/morphia/test/query/filters/in/example2/name new file mode 100644 index 00000000000..46162d39436 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/in/example2/name @@ -0,0 +1 @@ +Use the ``$in`` Operator with a Regular Expression \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/action.json new file mode 100644 index 00000000000..63df13e3a85 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { quantity: { $lt: 20 } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/data.json new file mode 100644 index 00000000000..c1d2781b7de --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/data.json @@ -0,0 +1,3 @@ +{ "item": "nuts", "quantity": 30, "carrier": { "name": "Shipit", "fee": 3 } }, +{ "item": "bolts", "quantity": 50, "carrier": { "name": "Shipit", "fee": 4 } }, +{ "item": "washers", "quantity": 10, "carrier": { "name": "Shipit", "fee": 1 } } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/expected.json new file mode 100644 index 00000000000..63066caffe8 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/expected.json @@ -0,0 +1 @@ +{ _id: ObjectId("61ba634dfe687fce2f04241f"), item: 'washers', quantity: 10, carrier: { name: 'Shipit', fee: 1 }} \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/name new file mode 100644 index 00000000000..f19ec4ead4e --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lt/example1/name @@ -0,0 +1 @@ +Match Document Fields \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/action.json new file mode 100644 index 00000000000..b5b71fc86b4 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { quantity: { $lte: 20 } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/data.json new file mode 100644 index 00000000000..c1d2781b7de --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/data.json @@ -0,0 +1,3 @@ +{ "item": "nuts", "quantity": 30, "carrier": { "name": "Shipit", "fee": 3 } }, +{ "item": "bolts", "quantity": 50, "carrier": { "name": "Shipit", "fee": 4 } }, +{ "item": "washers", "quantity": 10, "carrier": { "name": "Shipit", "fee": 1 } } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/expected.json new file mode 100644 index 00000000000..40834dfc07f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/expected.json @@ -0,0 +1 @@ +{ _id: ObjectId("61ba453ffe687fce2f04241c"), item: 'washers', quantity: 10, carrier: { name: 'Shipit', fee: 1 }} \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/name new file mode 100644 index 00000000000..f19ec4ead4e --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/lte/example1/name @@ -0,0 +1 @@ +Match Document Fields \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/data.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/data.json deleted file mode 100644 index 501ad468365..00000000000 --- a/core/src/test/resources/dev/morphia/test/query/filters/mod/data.json +++ /dev/null @@ -1,3 +0,0 @@ -{ "_id" : 1, "item" : "abc123", "qty" : 0 } -{ "_id" : 2, "item" : "xyz123", "qty" : 5 } -{ "_id" : 3, "item" : "ijk123", "qty" : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/action.json new file mode 100644 index 00000000000..9bbbeaf441b --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { qty: { $mod: [ 4, 0 ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/data.json new file mode 100644 index 00000000000..59bd56cc2eb --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/data.json @@ -0,0 +1,3 @@ +{ "_id" : 1, "item" : "abc123", "qty" : 0 }, +{ "_id" : 2, "item" : "xyz123", "qty" : 5 }, +{ "_id" : 3, "item" : "ijk123", "qty" : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/expected.json new file mode 100644 index 00000000000..a3e9140aaba --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/expected.json @@ -0,0 +1,2 @@ +{ '_id' : 1, 'item' : 'abc123', 'qty' : 0 }, +{ '_id' : 3, 'item' : 'ijk123', 'qty' : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/name new file mode 100644 index 00000000000..f14cf3506ed --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example1/name @@ -0,0 +1 @@ +Use ``$mod`` to Select Documents \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/action.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/action.json new file mode 100644 index 00000000000..cced5f3f734 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/action.json @@ -0,0 +1 @@ +db.inventory.find( { qty: { $mod: [ 4 ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/data.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/data.json new file mode 100644 index 00000000000..59bd56cc2eb --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/data.json @@ -0,0 +1,3 @@ +{ "_id" : 1, "item" : "abc123", "qty" : 0 }, +{ "_id" : 2, "item" : "xyz123", "qty" : 5 }, +{ "_id" : 3, "item" : "ijk123", "qty" : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/expected.json new file mode 100644 index 00000000000..8525f3cce4e --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/expected.json @@ -0,0 +1 @@ +MongoServerError: malformed mod, not enough elements \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/name b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/name new file mode 100644 index 00000000000..d3120521b87 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example2/name @@ -0,0 +1 @@ +Not Enough Elements Error \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/action.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/action.json new file mode 100644 index 00000000000..ce132bf3b50 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/action.json @@ -0,0 +1 @@ +db.inventory.find( { qty: { $mod: [ 4, 1, 2, 3 ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/data.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/data.json new file mode 100644 index 00000000000..59bd56cc2eb --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/data.json @@ -0,0 +1,3 @@ +{ "_id" : 1, "item" : "abc123", "qty" : 0 }, +{ "_id" : 2, "item" : "xyz123", "qty" : 5 }, +{ "_id" : 3, "item" : "ijk123", "qty" : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/expected.json new file mode 100644 index 00000000000..10820e3640f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/expected.json @@ -0,0 +1 @@ +MongoServerError: malformed mod, too many elements \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/name b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/name new file mode 100644 index 00000000000..e7231f89bdd --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example3/name @@ -0,0 +1 @@ +Too Many Elements Error \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/action.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/action.json new file mode 100644 index 00000000000..4cf58e82e68 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/action.json @@ -0,0 +1 @@ +db.inventory.find( { qty: { $mod: [ 4.0, 0.0 ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/data.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/data.json new file mode 100644 index 00000000000..59bd56cc2eb --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/data.json @@ -0,0 +1,3 @@ +{ "_id" : 1, "item" : "abc123", "qty" : 0 }, +{ "_id" : 2, "item" : "xyz123", "qty" : 5 }, +{ "_id" : 3, "item" : "ijk123", "qty" : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/expected.json new file mode 100644 index 00000000000..b5eaca93370 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/expected.json @@ -0,0 +1,2 @@ +{ _id: 1, item: 'abc123', qty: 0 }, +{ _id: 3, item: 'ijk123', qty: 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/lock b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/lock new file mode 100644 index 00000000000..982ce43de7d --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/lock @@ -0,0 +1 @@ +made the 0 a floating point to work the Java's type system \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/name b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/name new file mode 100644 index 00000000000..177a3dd274b --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example4/name @@ -0,0 +1 @@ +Floating Point Arguments \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/action.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/action.json new file mode 100644 index 00000000000..f6b751d724e --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/action.json @@ -0,0 +1 @@ +db.inventory.find( { qty: { $mod: [ -4, -0 ] } } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/data.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/data.json new file mode 100644 index 00000000000..59bd56cc2eb --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/data.json @@ -0,0 +1,3 @@ +{ "_id" : 1, "item" : "abc123", "qty" : 0 }, +{ "_id" : 2, "item" : "xyz123", "qty" : 5 }, +{ "_id" : 3, "item" : "ijk123", "qty" : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/expected.json new file mode 100644 index 00000000000..b5eaca93370 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/expected.json @@ -0,0 +1,2 @@ +{ _id: 1, item: 'abc123', qty: 0 }, +{ _id: 3, item: 'ijk123', qty: 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/name b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/name new file mode 100644 index 00000000000..fe8f477dffd --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/mod/example5/name @@ -0,0 +1 @@ +Negative Dividend \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/expected.json deleted file mode 100644 index 504bcd1519b..00000000000 --- a/core/src/test/resources/dev/morphia/test/query/filters/mod/expected.json +++ /dev/null @@ -1,2 +0,0 @@ -{ "_id" : 1, "item" : "abc123", "qty" : 0 } -{ "_id" : 3, "item" : "ijk123", "qty" : 12 } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/mod/query.json b/core/src/test/resources/dev/morphia/test/query/filters/mod/query.json deleted file mode 100644 index 83e6604a8d4..00000000000 --- a/core/src/test/resources/dev/morphia/test/query/filters/mod/query.json +++ /dev/null @@ -1 +0,0 @@ -{ qty: { $mod: [ 4, 0 ] } } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/near/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/near/example1/action.json new file mode 100644 index 00000000000..fb0bf3f42f4 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/near/example1/action.json @@ -0,0 +1,12 @@ +db.places.find( + { + location: + { $near : + { + $geometry: { type: "Point", coordinates: [ -73.9667, 40.78 ] }, + $minDistance: 1000.0, + $maxDistance: 5000.0 + } + } + } +) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/near/example1/lock b/core/src/test/resources/dev/morphia/test/query/filters/near/example1/lock new file mode 100644 index 00000000000..c18abb162ae --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/near/example1/lock @@ -0,0 +1 @@ +use floating point values \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/near/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/near/example1/name new file mode 100644 index 00000000000..96f9817864a --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/near/example1/name @@ -0,0 +1 @@ +Query on GeoJSON Data \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/near/example2/action.json b/core/src/test/resources/dev/morphia/test/query/filters/near/example2/action.json new file mode 100644 index 00000000000..88a21102f12 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/near/example2/action.json @@ -0,0 +1,3 @@ +db.legacy2d.find( + { location : { $near : [ -73.9667, 40.78 ], $maxDistance: 0.10 } } +) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/near/example2/name b/core/src/test/resources/dev/morphia/test/query/filters/near/example2/name new file mode 100644 index 00000000000..22b6a71a053 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/near/example2/name @@ -0,0 +1 @@ +Query on Legacy Coordinates \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/action.json new file mode 100644 index 00000000000..f83197250fa --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { quantity: { $nin: [ 5, 15 ] } }, { _id: 0 } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/data.json new file mode 100644 index 00000000000..24cc1e141ff --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/data.json @@ -0,0 +1,4 @@ +{ "item": "Pens", "quantity": 350, "tags": [ "school", "office" ] }, +{ "item": "Erasers", "quantity": 15, "tags": [ "school", "home" ] }, +{ "item": "Maps", "tags": [ "office", "storage" ] }, +{ "item": "Books", "quantity": 5, "tags": [ "school", "storage", "home" ] } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/expected.json new file mode 100644 index 00000000000..af8adf3ff7b --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/expected.json @@ -0,0 +1,2 @@ +{ item: 'Pens', quantity: 350, tags: [ 'school', 'office' ] }, +{ item: 'Maps', tags: [ 'office', 'storage' ] } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/name new file mode 100644 index 00000000000..6d7a4559113 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nin/example1/name @@ -0,0 +1 @@ +Select on Unmatching Documents \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nor/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/nor/example1/action.json new file mode 100644 index 00000000000..439225848ef --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nor/example1/action.json @@ -0,0 +1 @@ +db.inventory.find( { $nor: [ { price: 1.99 }, { sale: true } ] } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nor/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/nor/example1/name new file mode 100644 index 00000000000..8b964c9b854 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nor/example1/name @@ -0,0 +1 @@ +``$nor`` Query with Two Expressions \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nor/example2/action.json b/core/src/test/resources/dev/morphia/test/query/filters/nor/example2/action.json new file mode 100644 index 00000000000..622eb984257 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nor/example2/action.json @@ -0,0 +1 @@ +db.inventory.find( { $nor: [ { price: 1.99 }, { qty: { $lt: 20 } }, { sale: true } ] } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nor/example2/name b/core/src/test/resources/dev/morphia/test/query/filters/nor/example2/name new file mode 100644 index 00000000000..9bb6bf169ec --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nor/example2/name @@ -0,0 +1 @@ +``$nor`` and Additional Comparisons \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nor/example3/action.json b/core/src/test/resources/dev/morphia/test/query/filters/nor/example3/action.json new file mode 100644 index 00000000000..89b9b12d24f --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nor/example3/action.json @@ -0,0 +1,2 @@ +db.inventory.find( { $nor: [ { price: 1.99 }, { price: { $exists: false } }, + { sale: true }, { sale: { $exists: false } } ] } ) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/nor/example3/name b/core/src/test/resources/dev/morphia/test/query/filters/nor/example3/name new file mode 100644 index 00000000000..6f77fbb61ee --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/nor/example3/name @@ -0,0 +1 @@ +``$nor`` and ``$exists`` \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/action.json b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/action.json new file mode 100644 index 00000000000..3078b59707e --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/action.json @@ -0,0 +1,6 @@ +db.voters.find( + { district: 3, + $expr: { $lt: [0.5, {$rand: {} } ] } + }, + { _id: 0, name: 1, registered: 1 } +) \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/data.json b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/data.json new file mode 100644 index 00000000000..554d94c67fd --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/data.json @@ -0,0 +1,10 @@ +{ name: "Archibald", voterId: 4321, district: 3, registered: true }, +{ name: "Beckham", voterId: 4331, district: 3, registered: true }, +{ name: "Carolin", voterId: 5321, district: 4, registered: true }, +{ name: "Debarge", voterId: 4343, district: 3, registered: false }, +{ name: "Eckhard", voterId: 4161, district: 3, registered: false }, +{ name: "Faberge", voterId: 4300, district: 1, registered: true }, +{ name: "Grimwald", voterId: 4111, district: 3, registered: true }, +{ name: "Humphrey", voterId: 2021, district: 3, registered: true }, +{ name: "Idelfon", voterId: 1021, district: 4, registered: true }, +{ name: "Justo", voterId: 9891, district: 3, registered: false } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/expected.json b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/expected.json new file mode 100644 index 00000000000..1e4c3738697 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/expected.json @@ -0,0 +1,4 @@ +{ "name" : "Beckham", "registered" : true } +{ "name" : "Eckhard", "registered" : false } +{ "name" : "Grimwald", "registered" : true } +{ "name" : "Humphrey", "registered" : true } \ No newline at end of file diff --git a/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/name b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/name new file mode 100644 index 00000000000..d113a4d5147 --- /dev/null +++ b/core/src/test/resources/dev/morphia/test/query/filters/rand/example1/name @@ -0,0 +1 @@ +Select Random Items From a Collection \ No newline at end of file