Search code examples
javascriptmongodbloopback

How to set Model id to a string in Loopback?


I have a string that can be used to uniquely identify a Model instance, e.g., email - john@doe.com, which can be assigned to only one instance in the database, which means it won't be duped.

Now, how can I make this string from a variable to be assigned to a newly created instance automatically on creation?


Solution

  • I have just found it in the docs:

    In database terms, ID properties are primary key column(s) are. Such properties are defined with the 'id' attribute set to true or a number as the position for a composite key.

    {
        "myId": {
        "type": "string", 
        "id": true 
      }
    }