【发布时间】:2016-03-08 20:47:19
【问题描述】:
我有一个环回应用程序,它在创建模型时会提供像“56dbfa7089223aca7946ca14”这样的 ID。我更喜欢像“0”或“73”这样的ID。有没有办法调整 id 注入实践以使 id 从 0 开始并以 base-10 整数递增?
数据存储为 MongoDB v2.6.10) 在 Ubuntu 15.10 上的节点 v5.7.1 上运行环回 v2.22
这里是相关的model.json
{
"name": "Term",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"name": {
"type": "string",
"required": true
},
"beginDate": {
"type": "date",
"required": true
},
"endDate": {
"type": "date",
"required": true
}
},
"validations": [],
"relations": {
"lessons": {
"type": "hasMany",
"model": "Lesson",
"foreignKey": ""
},
"classes": {
"type": "hasMany",
"model": "Class",
"foreignKey": ""
},
"weeklySchedules": {
"type": "hasMany",
"model": "WeeklySchedule",
"foreignKey": ""
}
},
"acls": [],
"methods": {}
}
【问题讨论】:
-
我认为您正在使用 MongoDB 作为您的数据存储。生成的 ID 是 MongoDB 的默认 ObjectID,除非设置自己的 ID 并在模型配置中删除 idInjection,否则无法避免。
-
为什么不将此作为答案发布?
-
对此不是 100% 确定
-
请显示模型.json文件。
标签: node.js mongodb loopbackjs strongloop