2

There seems to have no way to enforce uniqueness in Parse. I have a parse object in which one of the fields is a url. I require that url to be unique as it is the most important field in the object: everything else is meta data about it. So is there a way to override the objectId of a Parse Object? That way I can always check for existence in a simple way before trying to create the object.

Actually this might still fail. So any ideas that do not include cloud code?

I know this can be done because Parse is able to ensure username and email are unique for each User object. I am hoping it's an elegant solution and someone here knows how I might accomplish something similar. After all, database tables with unique fields are commonplace.

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • Any reason why you don't want the check to be done in cloud code? – Mark Pazon Sep 21 '15 at 03:58
  • The cloud code version I have seen does not prevent interleaving in race conditions. So I don't want people pointing to it or code similar to it: https://www.parse.com/questions/unique-fields--2 – Katedral Pillon Sep 21 '15 at 18:08
  • I'd be curious to know how to do this myself... – Martin Erlic May 11 '18 at 03:02
  • https://stackoverflow.com/a/49393964/2764290 _To avoid race conditions, you should make the column/field unique. Do that in the database that you use with with Parse (if you use mongoDB with your parse server, then here's a link for mongoDB for example - https://docs.mongodb.com/manual/core/index-unique/). Then in CloudCode - try to create a new word object and store it. If the word already exists, the store will fail and then you can use a query to find the existing word and increment instead._ – Gifford N. Sep 30 '19 at 08:58

0 Answers0