Ren Hiyama
Ren Hiyama

Reputation: 479

Mongoose how to stop using _id (don't store it) and use id instead

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?

Upvotes: 0

Views: 1679

Answers (1)

Dori Lahav Waisberg
Dori Lahav Waisberg

Reputation: 980

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:

Upvotes: 1

Related Questions