LoopBack本身对我来说是新的,我发现版本4与版本3有很大不同。我的要求是,每次我创建一个POST到REST端点时,我需要在我的mongoDB文档中拥有一个自定义的自动递增ID,类似于MySQL数据库中的运行ID。
我检查了这个(auto-increment using loopback.js and MongoDB)和(https://gist.github.com/drmikecrowe/5a5568930bad567d4148aad75c94de5a),但是我没有找到适当的文档来在版本4上复制相同的内容。
目前,我正在使用一个基本应用程序,其中包含来自LoopBack 4提供的开箱即用的REST实现。以下是我的模型示例。
我检查了这个(auto-increment using loopback.js and MongoDB)和(https://gist.github.com/drmikecrowe/5a5568930bad567d4148aad75c94de5a),但是我没有找到适当的文档来在版本4上复制相同的内容。
目前,我正在使用一个基本应用程序,其中包含来自LoopBack 4提供的开箱即用的REST实现。以下是我的模型示例。
export class Test extends Entity {
@property({
type: 'string',
id: true,
})
_id?: string;
@property({
type: 'number',
generated: true,
required: false
})
id: number;
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'boolean',
required: true,
})
val: boolean;
constructor(data?: Partial<Test>) {
super(data);
}
}
我的MongoDB文档应该长成这样:
{
"_id" : ObjectId("5c373c1168d18c18c4382e00"),
"id" : 1
"name" : "aaaa",
"val" : true
}
{
"_id" : ObjectId("5c3869a55548141c0c27f298"),
"id" : 2
"name" : "bbbbb",
"val" : false
}