在mongodb中使用简单id not ObjectId

在mongodb中使用简单id not ObjectId,mongodb,spring-boot,Mongodb,Spring Boot,我想在客户端(angular)内的bdd mongodb中储存新集合。我有一个表格要填写,当我单击“提交”时,一个新集合将保存在mongodb中,如下所示: { "id": "5ede1268f363436aae8e52b0", "firstname": "adam", "lastname": "nebli", "email": "h@gmail.com" } void editTemplate ( String id , Template temp) {

我想在客户端(angular)内的bdd mongodb中储存新集合。我有一个表格要填写,当我单击“提交”时,一个新集合将保存在mongodb中,如下所示:

{
    "id": "5ede1268f363436aae8e52b0",
    "firstname": "adam",
    "lastname": "nebli",
    "email": "h@gmail.com"
 }
 void editTemplate ( String id , Template temp) {
 template = repo.findbyTempId(id);
 template.setemail(temp.getemail());
 template.setlastname(temp.getlastname());
 }
我的问题是我想要一个简单的id,而不是那样,因为我需要在我的编辑方法中使用它。我想创建这样一个方法:

{
    "id": "5ede1268f363436aae8e52b0",
    "firstname": "adam",
    "lastname": "nebli",
    "email": "h@gmail.com"
 }
 void editTemplate ( String id , Template temp) {
 template = repo.findbyTempId(id);
 template.setemail(temp.getemail());
 template.setlastname(temp.getlastname());
 }

如何设置mongo以创建具有简单id而非Objectid的集合?

您可以转换mongoDB提供的id。为此使用架构:

const testSchema=newmongoose.Schema({ 电邮:{ 类型:字符串, 要求:正确, }, 姓氏:{ 类型:字符串, 要求:正确, } }) testSchema.set('toJSON'{ 转换:(文档,返回对象)=>{ returnedObject.id=returnedObject.\u id.toString() 删除返回的对象。\u id 删除返回的对象 } }) module.exports=mongoose.model('Test',testSchema)
您可以转换mongoDB提供的id。为此使用架构:

const testSchema=newmongoose.Schema({ 电邮:{ 类型:字符串, 要求:正确, }, 姓氏:{ 类型:字符串, 要求:正确, } }) testSchema.set('toJSON'{ 转换:(文档,返回对象)=>{ returnedObject.id=returnedObject.\u id.toString() 删除返回的对象。\u id 删除返回的对象 } }) module.exports=mongoose.model('Test',testSchema)