SierraSoftworks / Iridium

A high performance MongoDB ORM for Node.js
http://sierrasoftworks.github.io/Iridium/
Other
569 stars 25 forks source link

Turnoff validation for @ObjectID #101

Closed rucas closed 6 years ago

rucas commented 7 years ago

This is a very specific case, I'm currently trying to migrate an old parse-server web app that created a bunch of _id's using a random alphanumeric generator of length 10.

I have some models that use the @ObjectID property that fail at validation during a lookup by _id, but work on creation. Is there anyway to turn off or override the validation?

notheotherben commented 7 years ago

Hi @rucas, I suspect the easiest solution to the issue you're facing is simply to replace all instances of @ObjectID with @Property(String) on those models which use non-ObjectID based _ids. If you want something a bit more specific, you should be able to use @Property(/^[A-Za-z0-9]{10}$/) to give you validation that it is indeed a subset of all the possible randomly generated, 10-character, IDs that your function produces.

class MyModel extends Instance<MyDoc, MyModel> {
  @Property(String)
  _id: string;
}