L
L
LinuxGod2020-02-14 12:21:11
Node.js
LinuxGod, 2020-02-14 12:21:11

How to disable _id in mongo collections?

Good day!
Need to disable _id in mongo collections at any cost, how to do it?
(I use mongoose as a mongo connector)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dima Pautov, 2020-02-14
@LinuxGod

It cannot be disabled, it is a unique id for each object. But you can override it by specifying your own value in the model. The only question is which one do you need! Well, there is and there is, what prevents it

L
lasthead, 2020-02-14
@lasthead

new mongoose.Schema({...}, {_id: false})
I've done it this way and it works. Naturally on newly added documents.

H
hzzzzl, 2020-02-14
@hzzzzl

maybe you want _id not to be specified in the sample?
Model.find({}, ' -_id' )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question