Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add supports for $and, $not, and $all for complex Mongo queries #50

Open
matthewp opened this issue Jul 17, 2019 · 1 comment
Open

Add supports for $and, $not, and $all for complex Mongo queries #50

matthewp opened this issue Jul 17, 2019 · 1 comment

Comments

@matthewp
Copy link
Contributor

No description provided.

@justinbmeyer
Copy link
Contributor

I pushed what we worked on into the and-all-not branch.

What I think needs to be done:

  1. A types/values-and.js needs to be created with a isMember 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
  1. You'll need to make serializers/basic-query.js able to hydrate to a structure like above. A test in serializers/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

  1. 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.

  2. Implement comparisons with $all. What is a union of {$all: ["a"]} and {$all: ["b"]}? I suspect that UNKNOWN will need to be the result. But that's ok.

  3. 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 a set.union( new GreaterThan(5), new All([5,6])) actually throws an error (as it does currently). After all, comparisons like GreaterThan() operate on a single key value. All() operates on an array of items. We might even want to make an array-comparisons.js and put All in there, so $elemMatch and $size could eventually land.

  4. ValueNot should probably be added to comparisons 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}

  5. We need to make serializing work for $not, $and, and $all

matthewp added a commit to canjs/can-memory-store that referenced this issue Jul 18, 2019
can-fixture uses the memory store, but its super set is the universal
set. Therefore there isn't a need to check if a query is a subset. Doing
so causes errors when comparisons are made between unknown types.

This is part of canjs/can-query-logic#50
matthewp added a commit to canjs/can-memory-store that referenced this issue Jul 18, 2019
can-fixture uses the memory store, but its super set is the universal
set. Therefore there isn't a need to check if a query is a subset. Doing
so causes errors when comparisons are made between unknown types.

This is part of canjs/can-query-logic#50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants