0

Since I will be listing my full database on /bots, and I want to use id instead of _id (discord uses id for everything, so I'm accustomed with id and not _id) I don't even want to save id as _id in the database. So any idea what to do?

Ren Hiyama
  • 383
  • 2
  • 13

1 Answers1

1

This is not possible!

MongoDB automatically creates an _id for every document that gets inserted into a database. This is there in order to give you a one-to-one value that you will be able to use to identify each document.

The id also contains a timestamp to when you inserted the document which then can be used to optimize queries using indexes.

This is also a best practice to send the _id to the user (even if it's mapped to an id field) to then be able to query more efficiently and also to not expose their Discord Id to everyone.

Hope I could answer your question. You could read more about it here:

  • Ok, but I found a good way for _id. Instead of sending random letters (objectId, the way mongodb says, I used `new Date` which is quite useful instead of old thingy. And I use id for discord stuff. – Ren Hiyama Mar 19 '21 at 11:53