mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Option to not create the collection when compiling model

Open ari-party opened this issue 1 year ago • 4 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Placing null in the collectionName argument should make it not create a collection for that model

Motivation

No response

Example

mongoose.model(name, schema, null)

ari-party avatar Jun 27 '23 10:06 ari-party

This is an interesting idea. What is the use case for this behavior? Is this mostly a way to create subdocuments?

vkarpov15 avatar Jul 02 '23 21:07 vkarpov15

This is an interesting idea. What is the use case for this behavior? Is this mostly a way to create subdocuments?

Lets you have a model that represents a log, you have multiple websites you want to have logs off. So to improve performance, you want to have the websites' logs in a different collection from each other.

Got it?

ari-party avatar Jul 02 '23 22:07 ari-party

That's an interesting idea. How would you change the log model's collection?

vkarpov15 avatar Jul 03 '23 13:07 vkarpov15

That's an interesting idea. How would you change the log model's collection?

Current way of doing it (tmk) is getting the mongo connection and inserting the document (const document = new Model()) into a collection Could add an option in document.save to set the collection.

ari-party avatar Jul 03 '23 14:07 ari-party