Unable to generate Object_id(random id) In Document DB

0

Hi Team,

I have migrated AWS RDS MySQL to AWS Document DB using DMS Service. all the data were migrated successfully but it's Object_id generating as like 1,2,3,... etc But i want to generate an Object_id like ObjectId("507f1f77bcf86cd799439011"), Is this possible to generate object_id like this? or else is there any other possible to generate object_id as like ObjectId("507f1f77bcf86cd799439011")

Kindly anyone help me to solve this issue.

1 個回答
0

AWS DocumentDB is a MongoDB-compatible database service, and it uses the BSON ObjectId format to generate unique identifiers for documents. The ObjectId format is a 12-byte binary value that consists of a timestamp, a machine identifier, a process identifier, and a counter.

But it looks like you are overwriting that in migration, there are 2 ways to handle that, you can insert new documents with an empty _id field and let DocumentDB generate a new ObjectId for each document.

Alternatively, you can generate new ObjectId values using Object mapping rules and following these steps:

Add new transformation rule for _id, use Expression Rule type. JavaScript code to generate a new ObjectId something like this

ObjectId(`${new Date().getTime().toString(16)}${Math.floor(Math.random()*10000000000000000).toString(16).padStart(16, '0')}`)
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南