Support Distinct for special fields (#5144)
* Support Distinct for special fields * update changelog
This commit is contained in:
@@ -710,19 +710,20 @@ export class MongoStorageAdapter implements StorageAdapter {
|
||||
schema = convertParseSchemaToMongoSchema(schema);
|
||||
const isPointerField =
|
||||
schema.fields[fieldName] && schema.fields[fieldName].type === 'Pointer';
|
||||
if (isPointerField) {
|
||||
fieldName = `_p_${fieldName}`;
|
||||
}
|
||||
const transformField = transformKey(className, fieldName, schema);
|
||||
|
||||
return this._adaptiveCollection(className)
|
||||
.then(collection =>
|
||||
collection.distinct(fieldName, transformWhere(className, query, schema))
|
||||
collection.distinct(
|
||||
transformField,
|
||||
transformWhere(className, query, schema)
|
||||
)
|
||||
)
|
||||
.then(objects => {
|
||||
objects = objects.filter(obj => obj != null);
|
||||
return objects.map(object => {
|
||||
if (isPointerField) {
|
||||
const field = fieldName.substring(3);
|
||||
return transformPointerString(schema, field, object);
|
||||
return transformPointerString(schema, fieldName, object);
|
||||
}
|
||||
return mongoObjectToParseObject(className, object, schema);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user