Skip to content

Commit 00571a6

Browse files
committed
Adds support for Long and Double mongodb types (fixes #1316)
1 parent af30f66 commit 00571a6

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

spec/transform.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
let transform = require('../src/transform');
55
let dd = require('deep-diff');
6+
let mongodb = require('mongodb');
67

78
var dummySchema = {
89
data: {},
@@ -241,4 +242,15 @@ describe('transform schema key changes', () => {
241242
done();
242243
});
243244

245+
it('untransforms mongodb number types', (done) => {
246+
var input = {
247+
long: mongodb.Long.fromInt(1234566778),
248+
double: new mongodb.Double(1234.3)
249+
}
250+
var output = transform.untransformObject(dummySchema, null, input);
251+
expect(output.long).toBe(1234566778);
252+
expect(output.double).toBe(1234.3);
253+
done();
254+
});
255+
244256
});

src/transform.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,14 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals
654654
return Parse._encode(mongoObject);
655655
}
656656

657+
if (mongoObject instanceof mongodb.Long) {
658+
return mongoObject.toNumber();
659+
}
660+
661+
if (mongoObject instanceof mongodb.Double) {
662+
return mongoObject.value;
663+
}
664+
657665
if (BytesCoder.isValidDatabaseObject(mongoObject)) {
658666
return BytesCoder.databaseToJSON(mongoObject);
659667
}

0 commit comments

Comments
 (0)