【发布时间】:2020-07-29 05:21:27
【问题描述】:
我想使用 _id(ObjectId) create 作为 mongoDB 上的唯一键作为我模型中的 id。
(对于一个 sql 数据库,我可以使用数据库的自动增量来控制它)
属性所在的模型:
@property({
type: 'number',
id: true,
generated: true,
})
_id?: number;
但是当我使用 URL 进行查找时,返回:
{
"_id": null,
"name": "sadsadsadasdasdsa",
"email": "string"
}
在 mongoDB 中: enter image description here
我如何检索 _id?
【问题讨论】:
-
我建议您将模型中的
type: 'number',更改为type: 'string',。还将_id?: number;更改为_id?: string;
标签: mongodb loopbackjs loopback4