Fix aggregate group id (#5994)

* Fix aggregate group id

* Improve implementation

* Add test case

* Fix postgres test - it does not work with group and sort at same time
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-09-01 22:34:36 -07:00
committed by GitHub
parent 5a482bd661
commit ac353ca8c2
2 changed files with 29 additions and 1 deletions

View File

@@ -285,6 +285,29 @@ describe('Parse.Query Aggregate testing', () => {
});
});
it('group by number', done => {
const options = Object.assign({}, masterKeyOptions, {
body: {
group: { objectId: '$score' },
},
});
get(Parse.serverURL + '/aggregate/TestObject', options)
.then(resp => {
expect(resp.results.length).toBe(2);
expect(
Object.prototype.hasOwnProperty.call(resp.results[0], 'objectId')
).toBe(true);
expect(
Object.prototype.hasOwnProperty.call(resp.results[1], 'objectId')
).toBe(true);
expect(
resp.results.sort((a, b) => (a.objectId > b.objectId ? 1 : -1))
).toEqual([{ objectId: 10 }, { objectId: 20 }]);
done();
})
.catch(done.fail);
});
it_exclude_dbs(['postgres'])('group and multiply transform', done => {
const obj1 = new TestObject({ name: 'item a', quantity: 2, price: 10 });
const obj2 = new TestObject({ name: 'item b', quantity: 5, price: 5 });

View File

@@ -799,7 +799,12 @@ export class MongoStorageAdapter implements StorageAdapter {
if (isPointerField && result._id) {
result._id = result._id.split('$')[1];
}
if (result._id == null || _.isEmpty(result._id)) {
if (
result._id == null ||
result._id == undefined ||
(['object', 'string'].includes(typeof result._id) &&
_.isEmpty(result._id))
) {
result._id = null;
}
result.objectId = result._id;