Skip to content

Fix: Add "Bytes" Field Type support to MongoSchemaCollection #1821

Closed
@netizen01

Description

@netizen01

I'm in the process of migrating my app and ran into a problem. One of my objects has a raw binary data field on it. After migrating my database to mLab, the SCHEMA for this object looks like this:

{
    "_id": "MyObject",
   ...
    "rawData": "bytes"
}

When using the new parse-server package, the server crashes when trying to decode the Binary data in this field. I've traced it down to:

MongoSchemaCollection->mongoFieldToParseSchemaField(type)

This function needs an extra case to handle the "bytes" type when it finds it in the SCHEMA. Here's the complete function that fixes the bug:

function mongoFieldToParseSchemaField(type) {
  if (type[0] === '*') {
    return {
      type: 'Pointer',
      targetClass: type.slice(1)
    };
  }
  if (type.startsWith('relation<')) {
    return {
      type: 'Relation',
      targetClass: type.slice('relation<'.length, type.length - 1)
    };
  }
  switch (type) {
    case 'number':
      return { type: 'Number' };
    case 'string':
      return { type: 'String' };
    case 'boolean':
      return { type: 'Boolean' };
    case 'date':
      return { type: 'Date' };
    case 'map':
    case 'object':
      return { type: 'Object' };
    case 'array':
      return { type: 'Array' };
    case 'geopoint':
      return { type: 'GeoPoint' };
    case 'file':
      return { type: 'File' };
    case 'bytes':
      return { type: 'Bytes' };
  }
}

I tried writing some test cases in the MongoTransform.spec.js but couldn't figure out the correct way of recreating the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions