0

I have been populating MongoDB collections with JSON data via MongoDB Compass using two methods:

Through the mongosh shell with the command:

mongoimport --jsonArray --authenticationDatabase admin --username <username> --password <password> -c <collection name> -d <database name> drop --file <filename>

and by importing the data through the Compass interface GUI when in the collection view.

Is there a way to set the primary key _id to generate a UUID instead of the ObjectID when populating the collection with a JSON file?

Using UUIDs instead of ObjectIDs in MongoDB is a discussion of the possibilities, pros, and cons of using UUIDs instead of ObjectIDs, but it doesn't discuss how to set the primary key to be a UUID instead of ObjectID, particularly when populating the database with JSON data.

interwebjill
  • 65
  • 2
  • 6
  • Does this answer your question? [Using UUIDs instead of ObjectIDs in MongoDB](https://stackoverflow.com/questions/28895067/using-uuids-instead-of-objectids-in-mongodb) – ray May 30 '22 at 03:47
  • @ray [Using UUIDs instead of ObjectIDs in MongoDB](https://stackoverflow.com/questions/28895067/using-uuids-instead-of-objectids-in-mongodb) is a discussion of the possibilities, pros, and cons of using UUIDs instead of ObjectIDs, but it doesn't discuss how to set the primary key to be a UUID instead of ObjectID, particularly when populating the database with JSON data. – interwebjill May 30 '22 at 04:09

0 Answers0