How to create ObjectId for document using Base64 ?

Problem Statement

Write mongoDB query for inserting document with ObjectId created from base64 text.

Collection Name: students

Insert below document in collection student. And use base64 string aGkgQ29kZWRpZ2d5 for objectid creation.

[
  {
    
    name: 'Joe Rogan',
    age: 35,
    country: 'USA'
  }
] 

To learn more about ObjectId and createFromBase64() : ObjectId.createFromBase64().

Solution

db.students.insertOne({
    _id:ObjectId.createFromBase64('aGkgQ29kZWRpZ2d5'),
    name: 'Joe Rogan',
    age: 35,
    country: 'USA',
})