is createCollection
in mongoose idempotent?
#15462
-
Hye guys, I was thinking if I call this method every time my app restarts, will that cause any issue? In my local env where I have a dockerized MongoDB instance with some existing documents in each collection it does not seem like it is destroying the existing collection and recreating it again. It is somewhat similar to |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
As you can see here it looks or at least logs are indicating that: https://github.com/kasir-barati/nestjs-materials/blob/916a35b80aec30a59448f1a8507084acf5eb3d74/mongoose/documentdb-index-creation/src/app/services/index.service.ts |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
createCollection()
is idempotent. Mongoose does sendcreateCollection()
onmongoose.connect()
for all models by default, you can disable that withmongoose.set('autoCreate', false)
.