-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Adding Mongodb element to add arrayMatches
the #4762
#4766
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
Conversation
@jeremypiednoel, can you add tests please and perhaps investigate what would be needed for supporting in Postgres as well please? |
@flovilmart Yes i'll write some test, it was just the first PR to discuss about the feature. |
Awesome thanks. So far I don’t see any issue :) with it |
All DB tests are in |
Some are there, also an edge to edge test. I still am not able to see how the current features prevent you doing what you expect :) |
Codecov Report
@@ Coverage Diff @@
## master #4766 +/- ##
==========================================
+ Coverage 92.69% 92.69% +<.01%
==========================================
Files 119 119
Lines 8635 8649 +14
==========================================
+ Hits 8004 8017 +13
- Misses 631 632 +1
Continue to review full report at Codecov.
|
here is my workaround const objects = [1,2,3,4,5,6,7,8].map((idx) => {
const obj = new Parse.Object('Object');
obj.set('key', idx);
return obj;
});
let parent3;
Parse.Object.saveAll(objects).then(() => {
const parent = new Parse.Object('Parent');
parent.set('objects', objects.slice(0, 3));
const shift = objects.shift();
const parent2 = new Parse.Object('Parent');
parent2.set('objects', [objects[1],shift]);
parent3 = new Parse.Object('Parent');
parent3.set('objects', objects.slice(1, 4));
return Parse.Object.saveAll([parent, parent2, parent3]);
}).then(() => {
const query = new Parse.Query('Parent');
query["_where"] = {
$nor : [{ objects : { $elemMatch : { $nin : objects.map(object => object.toPointer()) } }}]
};
return query.find();
}).then((result) => {
expect(parent3.id).toEqual(result[0].id);
expect(result.length).toBe(1);
}).then(done).catch(done.fail); so i use the double negative |
Not sure why you need the |
The condition is a -> find me all documents where none array have not all elements == find me all documents where all the items match |
Does it makes sense ? |
That’s very weird that you need to employ a double negation to do just that. I believe we missed something somewhere along the way as it feels overly complex for a query that feels so common. |
i made a lot of research and i found that : http://www.askasya.com/post/matchallarrayelements/ where the guy is doing exactly that. |
Also the mongodb $nor takes at least two queries, i’m Not sure why it’s working. |
The documentation says
https://docs.mongodb.com/manual/reference/operator/query/nor/ |
I also found this case where they use double negation as well : https://stackoverflow.com/questions/23595023/check-if-every-element-in-array-matches-condition |
So it's more
|
yes it's a very verbose but accurate naming. |
Do you still think it worth it to add it ? or it's a specific need that i should keep private ? |
@flovilmart i added tests. however i don't have any knowledge in Postgres |
Let's see if the test fails, as they should because those operators are not supported on postgresql. |
it looks like tests succeeded. |
I prefer not to have both supports separated as we may forget to implement it or worst be unable to provide a cross DB support |
Oh ok. Even if here we bring only the Core Mongo tools to make these queries? not the APIs. |
Let’s see how it goes for this one, but the operator chain look very specific to mongo, and perhaps we can create a parse specific operator that also work with Postgres :) |
@jeremypiednoel Can you write a few edge tests so we can play with? Postgres has https://www.postgresql.org/docs/9.4/static/functions-comparisons.html We can try to make it work. |
hey @dplewis, I wrote these tests already, and I will be happy to complete const array = [1, 2, 3, 4];
expect(() => validateQuery({
$and: [
{ 'a' : { $elemMatch : array }},
]
})).toThrow();
expect(() => validateQuery({
$nor: [
{ 'a' : { $elemMatch : 1 }},
]
})).toThrow();
const array = [1, 2, 3, 4];
expect(() => validateQuery({
$nor: [
{ 'a' : { $elemMatch : { $nin : array } }}
]
})).not.toThrow();
expect(() => validateQuery({
$and: [
{ 'a' : { $elemMatch : { $nin : array } }},
{ 'b' : { $elemMatch : { $all : array } }}
]
})).not.toThrow(); |
@jeremypiednoel How does this look? |
@dplewis it looks very good ! thanks for that. |
I can update the parse JS API and iOS SDK if you guys want with the |
That would be very neat :) |
Should we specify on the doc that this feature will be available only with the X.X version of parse server ? |
@flovilmart how does this look? |
@dplewis What do you think about adding the |
Depends if we have the equivalent easily with PG :)
…On May 18, 2018, 09:23 -0400, Jérémy Piednoel ***@***.***>, wrote:
@dplewis What do you think about adding the $nor support so we could also provide Parse.Query.nor() ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I might be wrong but I think it would be a combinaison of NOT and OR in postgresql. @dplewis ? |
@jeremypiednoel Feel free to open a separate PR with tests. That’s what I’m thinking for PG. |
Ok i will ! |
Let’s get this merged first. I’ll do the PHP and Android SDK. We still have to wait for the next release tho |
@dplewis I can put a release together now :) |
@jeremypiednoel Thanks for getting started on this. I’m still surprise this isn’t supported in mongo out of the box. I’ll open feature request on the mongo repo. @flovilmart Thanks. |
Yes i was surprised to but the documentation is pretty clear : its either |
this is very weird! |
…parse-community#4766) * Adding elemMatch and nor * lint * adding test * adding edge test * postgres support * clean up * empty test
No description provided.