Parse-server: Q: how to define database schema? e.g. define a column as unique.

Created on 3 Aug 2017  路  6Comments  路  Source: parse-community/parse-server

I'm new to parse-server. I'm trying to find a way to define a database schema. So that when I save an object, it'll check if one field of the object is unique in the class.

All 6 comments

Parse Server manages the schema for you. Whenever you create an object and set a field, it will check if that object already has a type on that field. If it does, it will not allow saving a different type for that field; if it doesn't have yet, it will set that field to be of the type you set.

@natanrolnik what about setting a field unique?

This is currently not supported; you would need to do it in the database level I believe. @flovilmart might have a better answer.

@flovilmart whats your take?

You can use indexes in both mongo or Postgres to enforce uniqueness for a particular column

The API for schema also illustrates that, thanks,

const schema = new Parse.Schema('MyClass');
schema.addString('field');
schema.addIndex('index_name', {'field', 1}, { unique : true });
schema.save();

Was this page helpful?
0 / 5 - 0 ratings