loopback
loopback copied to clipboard
Model 'id' instance as a number
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?
Please post questions at https://groups.google.com/forum/#!forum/loopbackjs. See https://github.com/strongloop/loopback/wiki/Reporting-issues#question for more details.