Skip to content

Commit 868e7e3

Browse files
committed
fix: query fails on nested date attributes
1 parent 5eea57b commit 868e7e3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Adapters/Storage/Mongo/MongoTransform.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function transformQueryKeyValue(className, key, value, schema, count = false) {
316316
}
317317

318318
// Handle query constraints
319-
const transformedConstraint = transformConstraint(value, field, count);
319+
const transformedConstraint = transformConstraint(value, field, count, key);
320320
if (transformedConstraint !== CannotTransform) {
321321
if (transformedConstraint.$text) {
322322
return { key: '$text', value: transformedConstraint.$text };
@@ -561,8 +561,6 @@ const transformInteriorAtom = atom => {
561561
};
562562
} else if (typeof atom === 'function' || typeof atom === 'symbol') {
563563
throw new Parse.Error(Parse.Error.INVALID_JSON, `cannot transform value: ${atom}`);
564-
} else if (DateCoder.isValidJSON(atom)) {
565-
return DateCoder.JSONToDatabase(atom);
566564
} else if (BytesCoder.isValidJSON(atom)) {
567565
return BytesCoder.JSONToDatabase(atom);
568566
} else if (typeof atom === 'object' && atom && atom.$regex !== undefined) {
@@ -766,12 +764,15 @@ function relativeTimeToDate(text, now = new Date()) {
766764
// If it is not a valid constraint but it could be a valid something
767765
// else, return CannotTransform.
768766
// inArray is whether this is an array field.
769-
function transformConstraint(constraint, field, count = false) {
767+
function transformConstraint(constraint, field, count = false, restKey) {
770768
const inArray = field && field.type && field.type === 'Array';
771769
if (typeof constraint !== 'object' || !constraint) {
772770
return CannotTransform;
773771
}
774-
const transformFunction = inArray ? transformInteriorAtom : transformTopLevelAtom;
772+
// if key points to nested attribute, we don't want to transform types other than Bytes, so that we're consistent with
773+
// how we're saving nested attributes
774+
const transformFunction =
775+
inArray || (restKey && restKey.includes('.')) ? transformInteriorAtom : transformTopLevelAtom;
775776
const transformer = atom => {
776777
const result = transformFunction(atom, field);
777778
if (result === CannotTransform) {

0 commit comments

Comments
 (0)