Support pointer in distinct query (#4471)

* Support pointer in distinct query

* extract transform pointer string
This commit is contained in:
Diamond Lewis
2017-12-29 21:32:40 -06:00
committed by GitHub
parent 7d773a5d8a
commit 6143988a82
4 changed files with 66 additions and 16 deletions

View File

@@ -10,6 +10,7 @@ import {
transformKey,
transformWhere,
transformUpdate,
transformPointerString,
} from './MongoTransform';
import Parse from 'parse/node';
import _ from 'lodash';
@@ -483,9 +484,19 @@ export class MongoStorageAdapter {
distinct(className, schema, query, fieldName) {
schema = convertParseSchemaToMongoSchema(schema);
const isPointerField = schema.fields[fieldName] && schema.fields[fieldName].type === 'Pointer';
if (isPointerField) {
fieldName = `_p_${fieldName}`
}
return this._adaptiveCollection(className)
.then(collection => collection.distinct(fieldName, transformWhere(className, query, schema)))
.then(objects => objects.map(object => mongoObjectToParseObject(className, object, schema)));
.then(objects => objects.map(object => {
if (isPointerField) {
const field = fieldName.substring(3);
return transformPointerString(schema, field, object);
}
return mongoObjectToParseObject(className, object, schema);
}));
}
aggregate(className, schema, pipeline, readPreference) {