Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal
Enhance the Model.create()
method to allow passing an options
argument when creating a single document. Currently, this is only possible when documents are passed as an array, which is inconvenient for cases where only a single document needs to be created.
Motivation
The current implementation of the Model.create()
method requires documents to be passed as an array when using the options
argument, even if only a single document is being created. This approach is less intuitive and can lead to unnecessary complexity, such as having to handle an array in return when only a single document is expected. Allowing the options
argument to be used with a single document directly would result in cleaner, more straightforward code and avoid the need to deal with array structures when they aren't necessary.
Example
Current Implementation:
const [document] = await model.create(
[
{
name: 'example',
},
],
{
session: ClientSession,
},
);
Proposed Implementation:
const document = await model.create(
{
name: 'example',
},
{
session: ClientSession,
},
);