Loopback 将对象 ID 值作为序列而不是随机插入 - 我该如何更改它?
Loopback inserts object id values as sequence and not random - how can i change it?
Loopback 为我的 MongoDB 插入对象 ID 值作为序列而不是随机的。
出于安全原因,我如何将所有模型的默认设置为随机?
会影响数据库性能吗?
您可以在模型的描述文件中更改 ID 的生成方式:
https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#properties
model.json:
{
"name": "model",
"base": "PersistedModel",
"strict": true,
"idInjection": false, // disable default id!
"properties": {
"id": {
"id": true,
"required": true,
"type": "string",
"defaultFn": "uuid" // "guid" / "uuid" / "uuidv4" / "now"
},
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
Loopback 为我的 MongoDB 插入对象 ID 值作为序列而不是随机的。 出于安全原因,我如何将所有模型的默认设置为随机?
会影响数据库性能吗?
您可以在模型的描述文件中更改 ID 的生成方式: https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#properties
model.json:
{
"name": "model",
"base": "PersistedModel",
"strict": true,
"idInjection": false, // disable default id!
"properties": {
"id": {
"id": true,
"required": true,
"type": "string",
"defaultFn": "uuid" // "guid" / "uuid" / "uuidv4" / "now"
},
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}