Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Custom collection name support #233

Closed
Josuto opened this issue May 8, 2024 · 3 comments
Closed

Custom collection name support #233

Josuto opened this issue May 8, 2024 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@Josuto
Copy link
Owner

Josuto commented May 8, 2024

Good day,

First and foremost, thank you for this excellent project. Has the possibility to let the implementation of MongooseRepository decide on the name of the underlying collection it will use, been explored before? I'd be happy to assist should you approve the idea.

Thanks again for monguito!

Best wishes,
Rijk

Originally posted by @rijkdw in #230

@Josuto Josuto self-assigned this May 8, 2024
@Josuto Josuto added the question Further information is requested label May 8, 2024
@Josuto
Copy link
Owner Author

Josuto commented May 8, 2024

Hi Rijk!

It turns out that there is an easy way to provide a custom name for collections without having to perform any updates in Monguito's code base 😙. As you may know, Monguito wraps Mongoose to benefit from some resources such as Schema. The constructor of this type specifies collection as an optional parameter that you can use to define a name for the collection modelled by a schema. Here's an example of how you would do it:

export const BookSchema = extendSchema(
  BaseSchema,
  {
    title: { type: String, required: true },
    description: { type: String, required: false },
    edition: { type: Number, required: true },
  },
  { collection: 'AwesomeBooks' },
);

Please let me know if that answers your question 😊

@rijkdw
Copy link

rijkdw commented May 8, 2024

Ahh, it does. I was aware of setting the collection name upon creation of the Model, but not of the Schema. Thank you @Josuto 🙇‍♂️

@Josuto
Copy link
Owner Author

Josuto commented May 8, 2024

My pleasure, @rijkdw! Please keep on sharing any doubts or ideas you may have 😉

@Josuto Josuto closed this as completed May 8, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants