loopback icon indicating copy to clipboard operation
loopback copied to clipboard

Model 'id' instance as a number

Open bebop23 opened this issue 11 years ago • 1 comments

I have the following model definition:

{
  "name": "Device",
  "base": "PersistedModel",
  "strict": true,
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "name": {
      "type": "string"
    },
    "description": {
      "type": "string"
    },
    "host": {
      "type": "string",
      "required": true
    },
    "password": {
      "type": "string",
      "required": true
    },
    "id": {
      "type": "number",
      "id": true,
      "generated": true
    },
    "user": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": []
}

This model uses mongodb as a datasource. I want the 'id' to a auto-incrementing, unique number that loopback generates (1, 2, 3....456, etc) , however, when I create a record, it uses a string instead as the id.

Here is the json I get back after I perform a POST operation on the model's corresponding REST endpoint:

{
    "host": "172.1.12.10",
    "password": "admin",
    "id": "5594e671fb6d1db56a9176ce",
    "user": "admin"
}

How do I ensure that the 'id' fields uses a number instead?

bebop23 avatar Jul 02 '15 07:07 bebop23

Please post questions at https://groups.google.com/forum/#!forum/loopbackjs. See https://github.com/strongloop/loopback/wiki/Reporting-issues#question for more details.

superkhau avatar Jul 06 '15 18:07 superkhau