Skip to content

Commit

Permalink
Adds support for Long and Double mongodb types (fixes #1316)
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Apr 12, 2016
1 parent af30f66 commit 5d2d563
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/transform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

let transform = require('../src/transform');
let dd = require('deep-diff');
let mongodb = require('mongodb');

var dummySchema = {
data: {},
Expand Down Expand Up @@ -241,4 +242,15 @@ describe('transform schema key changes', () => {
done();
});

fit('untransforms mongodb number types', (done) => {
var input = {
long: mongodb.Long.fromInt(1234566778),
double: new mongodb.Double(1234.3)
}
var output = transform.untransformObject(dummySchema, null, input);
expect(output.long).toBe(1234566778);
expect(output.double).toBe(1234.3);
done();
});

});
8 changes: 8 additions & 0 deletions src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,14 @@ function untransformObject(schema, className, mongoObject, isNestedObject = fals
return Parse._encode(mongoObject);
}

if (mongoObject instanceof mongodb.Long) {
return mongoObject.toNumber();
}

if (mongoObject instanceof mongodb.Double) {
return mongoObject.value;
}

if (BytesCoder.isValidDatabaseObject(mongoObject)) {
return BytesCoder.databaseToJSON(mongoObject);
}
Expand Down

0 comments on commit 5d2d563

Please sign in to comment.