0
我正在尝试使用MongoDB
来实现Loopback 3.0.0
的组合ID。每对product_id/keyword
应该是唯一的......如何在Loopback中使用组合ID?
我检查的官方文档:
https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#data-mapping-properties
这里我的模型:
{
"name": "comparative",
"plural": "comparative",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"product_id": {
"id": true,
"type": "string",
"required": true
},
"keyword": {
"id": true,
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
虽然,我所有的努力,使复合IDS product_id /关键字失败。
发帖时:
// 1st POST Success.
{
"product_id": "string",
"keyword": "string"
}
// 2nd POST Success.
{
"product_id": "string1",
"keyword": "string"
}
// 3rd POST FAILED -> I want it to success
{
"product_id": "string",
"keyword": "string1"
}
任何想法?
即使在那之后,我需要保留一个自动生成的MongoDB id
只是为了跟踪对象。
我试着用“idInjection”,不能与复合ID一起工作......(不会产生任何东西......) 如果我添加另一个字段“id”,生成的设置为true,复合id不起作用所有(相反由于其开展部分之前)
谢谢