Skip to content

query using pointers in deep sub-documents #7426

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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a7fd0ea
test and code
oallouch Jun 9, 2021
3973c5f
start of changelog update
oallouch Jun 9, 2021
bea4707
fix: package.json & package-lock.json to reduce vulnerabilities (#7423)
snyk-bot Jun 10, 2021
61affe2
fix: upgrade mongodb from 3.6.6 to 3.6.7 (#7425)
snyk-bot Jun 10, 2021
bfdb6a9
fix: upgrade apollo-server-express from 2.24.0 to 2.24.1 (#7424)
snyk-bot Jun 10, 2021
0638e5e
chore(deps): bump normalize-url from 4.5.0 to 4.5.1 (#7428)
dependabot[bot] Jun 10, 2021
f6a4172
bump mongo (#7429)
mtrezza Jun 11, 2021
6deb7ec
restriction to mongo testing
oallouch Jun 12, 2021
1069519
CHANGELOG: typo fix braking->breaking [ci skip] (#7432)
olleolleolle Jun 15, 2021
3a2afda
bump node version (#7441)
mtrezza Jun 20, 2021
d8dc524
Add check for property (#7421)
Jun 21, 2021
770e36f
fix: upgrade graphql-relay from 0.6.0 to 0.7.0 (#7443)
snyk-bot Jun 24, 2021
7df6c02
fix: upgrade ldapjs from 2.2.4 to 2.3.0 (#7436)
snyk-bot Jun 24, 2021
4e5eba6
fix: upgrade apollo-server-express from 2.24.1 to 2.25.0 (#7435)
snyk-bot Jun 24, 2021
c36588e
fix: upgrade mongodb from 3.6.7 to 3.6.8 (#7430)
snyk-bot Jun 24, 2021
17cf1a4
fix: upgrade mongodb from 3.6.8 to 3.6.9 (#7445)
snyk-bot Jun 28, 2021
d36a53b
fix: upgrade subscriptions-transport-ws from 0.9.19 to 0.10.0 (#7450)
snyk-bot Jun 30, 2021
682f1bf
fix: upgrade apollo-server-express from 2.25.0 to 2.25.1 (#7449)
snyk-bot Jun 30, 2021
05882bc
bumped node (#7452)
mtrezza Jul 3, 2021
1594afe
add runtime deprecation warning (#7451)
mtrezza Jul 12, 2021
6a39cfe
test and code
oallouch Jun 9, 2021
3efe6f6
fix changelog message
oallouch Jul 13, 2021
5b82047
restriction to mongo testing
oallouch Jun 12, 2021
2ea03da
Merge branch 'deep-nested-pointers' of https://github.com/oallouch/pa…
oallouch Jul 13, 2021
0e215ea
unnecessary comments removal
oallouch Jul 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ ___
- Add NPM package-lock version check to CI (Manuel Trezza) [#7333](https://github.com/parse-community/parse-server/pull/7333)
- Fix incorrect LiveQuery events triggered for multiple subscriptions on the same class with different events [#7341](https://github.com/parse-community/parse-server/pull/7341)
- Fix select and excludeKey queries to properly accept JSON string arrays. Also allow nested fields in exclude (Corey Baker) [#7242](https://github.com/parse-community/parse-server/pull/7242)
- Fix querying deep nested pointers (Olivier Allouch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please adapt format, see other entries


___
## 4.5.0
Expand Down
34 changes: 34 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4318,6 +4318,40 @@ describe('Parse.Query testing', () => {
}
});

it_only_db('mongo')('deeply nested Pointers (issue #7413)', async function (done) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only a bug in MongoDB, or is this a feature that only works in MongoDB? If the first, then the test should not be exclusively for MongoDB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know how PostgreSQL works with parse-server, but I think it must be MongoDB only. How sub-documents work in an SQL db ?

const parent = new Parse.Object('Parent');
const child1 = new Parse.Object('Child');
const child2 = new Parse.Object('Child');

parent.set('subDocument', { child: child1 });
parent.set('children', [
{ child: child1, count: 2 },
{ child: child2, count: 3 },
]);
await parent.save();

// equalTo
const resultsEq = await new Parse.Query('Parent').equalTo('children.child', child1).find();
expect(resultsEq.length).toBe(1);

// direct subDocument equalTo
const resultsSubDocument = await new Parse.Query('Parent')
.equalTo('subDocument.child', child1)
.find();
expect(resultsSubDocument.length).toBe(1);

// subDocument in
const resultsSubDocumentIn = await new Parse.Query('Parent')
.containedIn('subDocument.child', [child1])
.find();
expect(resultsSubDocumentIn.length).toBe(1);

// containedIn
const results = await new Parse.Query('Parent').containedIn('children.child', [child1]).find();
expect(results.length).toBe(1);
done();
});

it('include with *', async () => {
const child1 = new TestObject({ foo: 'bar', name: 'ac' });
const child2 = new TestObject({ foo: 'baz', name: 'flo' });
Expand Down
13 changes: 9 additions & 4 deletions src/Adapters/Storage/Mongo/MongoTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function transformQueryKeyValue(className, key, value, schema, count = false) {
}

// Handle query constraints
const transformedConstraint = transformConstraint(value, field, count);
const transformedConstraint = transformConstraint(value, key, field, count);
if (transformedConstraint !== CannotTransform) {
if (transformedConstraint.$text) {
return { key: '$text', value: transformedConstraint.$text };
Expand Down Expand Up @@ -766,19 +766,24 @@ function relativeTimeToDate(text, now = new Date()) {
// If it is not a valid constraint but it could be a valid something
// else, return CannotTransform.
// inArray is whether this is an array field.
function transformConstraint(constraint, field, count = false) {
const inArray = field && field.type && field.type === 'Array';
function transformConstraint(constraint, restKey, field, count = false) {
if (typeof constraint !== 'object' || !constraint) {
return CannotTransform;
}
const transformFunction = inArray ? transformInteriorAtom : transformTopLevelAtom;

// transformer
const inArray = field && field.type && field.type === 'Array';
const inSubDocument = restKey.includes('.');
const transformFunction =
inArray || inSubDocument ? transformInteriorAtom : transformTopLevelAtom;
const transformer = atom => {
const result = transformFunction(atom, field);
if (result === CannotTransform) {
throw new Parse.Error(Parse.Error.INVALID_JSON, `bad atom: ${JSON.stringify(atom)}`);
}
return result;
};

// keys is the constraints in reverse alphabetical order.
// This is a hack so that:
// $regex is handled before $options
Expand Down