Иво Стратев
Иво Стратев

Reputation: 415

Stop Monk from adding _id to docs

Is there a way to stop monk from generating and adding _id to docs ? Or is there a driver for MongoDb in Node.js that doesn't auto add _id ?

Upvotes: 0

Views: 1779

Answers (2)

IrfanAnwar
IrfanAnwar

Reputation: 79

db.createCollection("noautoid", { autoIndexId: false });

This will create a collection without _id but the option is deprecated and will be removed in next versions.

Upvotes: 0

Lalit Agarwal
Lalit Agarwal

Reputation: 2354

_id is needed in every doc. If you don't want auto generated _id then you have to add a custom one. But every doc should have _id in mongo.

You can add your own _id and insert it when inserting doc. Just make sure _id is unique across all docs in a collection. It should be what primary key is in RDBMS.

Upvotes: 1

Related Questions