Support for Aggregate Queries (#4207)
* Support for Aggregate Queries * improve pg and coverage * Mongo 3.4 aggregates and tests * replace _id with objectId * improve tests for objectId * project with group query * typo
This commit is contained in:
committed by
Florent Vilmart
parent
4e207d32a7
commit
7223add446
@@ -405,6 +405,27 @@ export class MongoStorageAdapter {
|
||||
}));
|
||||
}
|
||||
|
||||
distinct(className, schema, query, fieldName) {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection => collection.distinct(fieldName, transformWhere(className, query, schema)));
|
||||
}
|
||||
|
||||
aggregate(className, pipeline, readPreference) {
|
||||
readPreference = this._parseReadPreference(readPreference);
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection => collection.aggregate(pipeline, { readPreference, maxTimeMS: this._maxTimeMS }))
|
||||
.then(results => {
|
||||
results.forEach(result => {
|
||||
if (result.hasOwnProperty('_id')) {
|
||||
result.objectId = result._id;
|
||||
delete result._id;
|
||||
}
|
||||
});
|
||||
return results;
|
||||
});
|
||||
}
|
||||
|
||||
_parseReadPreference(readPreference) {
|
||||
if (readPreference) {
|
||||
switch (readPreference) {
|
||||
|
||||
Reference in New Issue
Block a user