Adding Mongodb element to add arrayMatches the #4762 (#4766)

* Adding elemMatch and nor

* lint

* adding test

* adding edge test

* postgres support

* clean up

* empty test
This commit is contained in:
Jérémy Piednoel
2018-05-18 09:35:50 -04:00
committed by Diamond Lewis
parent ad244d6654
commit c0f86ae1d1
3 changed files with 133 additions and 0 deletions

View File

@@ -290,6 +290,9 @@ function transformQueryKeyValue(className, key, value, schema) {
if (transformedConstraint.$text) {
return {key: '$text', value: transformedConstraint.$text};
}
if (transformedConstraint.$elemMatch) {
return { key: '$nor', value: [{ [key]: transformedConstraint }] };
}
return {key, value: transformedConstraint};
}
@@ -797,6 +800,19 @@ function transformConstraint(constraint, field) {
answer[key] = s;
break;
case '$containedBy': {
const arr = constraint[key];
if (!(arr instanceof Array)) {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
`bad $containedBy: should be an array`
);
}
answer.$elemMatch = {
$nin: arr.map(transformer)
};
break;
}
case '$options':
answer[key] = constraint[key];
break;

View File

@@ -446,6 +446,20 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
index += 1;
}
if (fieldValue.$containedBy) {
const arr = fieldValue.$containedBy;
if (!(arr instanceof Array)) {
throw new Parse.Error(
Parse.Error.INVALID_JSON,
`bad $containedBy: should be an array`
);
}
patterns.push(`$${index}:name <@ $${index + 1}::jsonb`);
values.push(fieldName, JSON.stringify(arr));
index += 2;
}
if (fieldValue.$text) {
const search = fieldValue.$text.$search;
let language = 'english';