在进行 ID 注入时,如何让 Loopback 更喜欢短 ID?

How do I get Loopback to prefer short ids when doing id injection?

我有一个环回应用程序,它在创建模型时提供类似“56dbfa7089223aca7946ca14”的 ID。我更喜欢像“0”或“73”这样的 ID。有没有办法调整 id 注入实践,使 id 从 0 开始并以 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": {}
}

有几种方法可以做到,你可以在官方阅读它们documentation

mongo开发者说的,完全可以,用你自己的id,如果你真的需要,那就去吧。

但是,如果你这样做只是因为你"dont want ObjectId, because it does not look good",我建议你习惯它。