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:
committed by
GitHub
parent
5a482bd661
commit
ac353ca8c2
@@ -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 => {
|
it_exclude_dbs(['postgres'])('group and multiply transform', done => {
|
||||||
const obj1 = new TestObject({ name: 'item a', quantity: 2, price: 10 });
|
const obj1 = new TestObject({ name: 'item a', quantity: 2, price: 10 });
|
||||||
const obj2 = new TestObject({ name: 'item b', quantity: 5, price: 5 });
|
const obj2 = new TestObject({ name: 'item b', quantity: 5, price: 5 });
|
||||||
|
|||||||
@@ -799,7 +799,12 @@ export class MongoStorageAdapter implements StorageAdapter {
|
|||||||
if (isPointerField && result._id) {
|
if (isPointerField && result._id) {
|
||||||
result._id = result._id.split('$')[1];
|
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._id = null;
|
||||||
}
|
}
|
||||||
result.objectId = result._id;
|
result.objectId = result._id;
|
||||||
|
|||||||
Reference in New Issue
Block a user