Add supports for $and, $not, and $all for complex Mongo queries
matthewp opened this issue · comments
I pushed what we worked on into the and-all-not
branch.
What I think needs to be done:
- A
types/values-and.js
needs to be created with aisMember
method. It should work something like:
new ValuesAnd([
new KeysAnd({tags: new is.All(['sbux']) }),
new KeysAnd({tags: new ValuesNot( new is.All(['dfw']) })
]).isMember({
tags: ["sbux"]
}) //-> true
- You'll need to make
serializers/basic-query.js
able to hydrate to a structure like above. A test inserializers/basic-query-test.js
should look like:
var query = {
filter: {
$and: [
{tags: {$all: ['sbux']}},
{tags: {$not: {$all: ['dfw']}}}
]
}
};
var converter = makeBasicQueryConvert(EmptySchema);
var basicQuery = converter.hydrate(query);
assert(basicQuery.filter instanceof ValuesAnd);
this test is already started
-
If everything prior to this is working, you should be able to see if your fixtures work. If they do, that's great. Though there's some extra work to make sure
$not
,$all
and$and
really work in anything but your exact scenario. -
Implement comparisons with $all. What is a union of
{$all: ["a"]}
and{$all: ["b"]}
? I suspect thatUNKNOWN
will need to be the result. But that's ok. -
Implement comparisons and tests with
$all
and all the other operators. For the most part, I think we might be able to actually test that trying to do aset.union( new GreaterThan(5), new All([5,6]))
actually throws an error (as it does currently). After all, comparisons likeGreaterThan()
operate on a single key value.All()
operates on an array of items. We might even want to make an array-comparisons.js and putAll
in there, so$elemMatch
and$size
could eventually land. -
ValueNot
should probably be added tocomparisons
and tested that way. Or its hydration should be able to invert most comparisons.For example, we should be able to do something like
union( new ValueNot( new LessThan(5 ) ), new LessThan(5) )
But, if someone tried to hydrate
{$not: {$lt: 5}}
this should really be hydrated to{$gte: 5}
-
We need to make serializing work for $not, $and, and $all