Skip to content

Adds support for Long and Double mongodb types (fixes #1316) #1470

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

Merged
merged 2 commits into from
Apr 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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();
});

it('untransforms mongodb number types', (done) => {
var input = {
long: mongodb.Long.fromNumber(Number.MAX_SAFE_INTEGER),
double: new mongodb.Double(Number.MAX_VALUE)
}
var output = transform.untransformObject(dummySchema, null, input);
expect(output.long).toBe(Number.MAX_SAFE_INTEGER);
expect(output.double).toBe(Number.MAX_VALUE);
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