[英]TypeScript- Custom Object ID instead of Default MongoDB Object ID
I am getting default MongoDB Object ID from MongoDB by using Typescript. 我通过使用Typescript从MongoDB获取默认的MongoDB对象ID。 How can I get Custom ID instead of default MongoDB Object ID ?
如何获取自定义ID而不是默认的MongoDB对象ID?
{ "_id": " 5bbe053ab10bdf08964443d5 ", "title": " Moto Z", "manufacture_details": { "brand": "Motorola", "model_number": "XT1650" } }
{“ _id”:“ 5bbe053ab10bdf08964443d5 ”,“ title”:“ Moto Z”,“ manufacture_details”:{“ brand”:“ Motorola”,“ model_number”:“ XT1650”}}
This is my Model.ts 这是我的Model.ts
import * as mongoose from 'mongoose';
const Schema = mongoose.Schema;
export const ProductSchema = new Schema({
title: {
type: String,
},
manufacture_details: {
brand: String,
model_number: String,
},
});
I Updated the Model.ts with a new field _id which will be overwriting the default Object ID 我用新的字段_id更新了Model.ts,它将覆盖默认的对象ID。
import * as mongoose from 'mongoose';
const Schema = mongoose.Schema;
export const ProductSchema = new Schema({
_id: {
type: String,
},
title: {
type: String,
},
manufacture_details: {
brand: String,
model_number: String,
},
});
Now i am able to get Custom Object ID 现在我可以获取自定义对象ID
{ "_id": "M01", "title": " Moto Z", "manufacture_details": { "brand": "Motorola", "model_number": "XT1650" } }
{“ _id”:“ M01”,“ title”:“ Moto Z”,“ manufacture_details”:{“ brand”:“ Motorola”,“ model_number”:“ XT1650”}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.