Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

model.createCollection fails for capped collection when using capped: number #11539

Closed
mhassan1 opened this issue Mar 17, 2022 · 1 comment
Closed
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@mhassan1
Copy link

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?

Calling model.createCollection for a model that specifies capped: number throws an error: MongoServerError: the 'size' field is required when 'capped' is true. Specifying capped: { size: number } instead throws no error.

If the current behavior is a bug, please provide the steps to reproduce.

await mongoose.model('thing', new mongoose.Schema({ name: String }, { capped: 100 })).createCollection()
// -> MongoServerError: the 'size' field is required when 'capped' is true

await mongoose.model('thing', new mongoose.Schema({ name: String }, { capped: { size: 100 } })).createCollection()
// -> no error

It seems like the logic at

options = Object.assign({ capped: true }, capped, options);
does not properly account for the capped: number scenario.

What is the expected behavior?

No error is thrown

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

node: 16.14.0
mongoose: 6.2.4
mongodb: 4.4

@IslandRhythms
Copy link
Collaborator

const mongoose = require('mongoose');

const failSchema = new mongoose.Schema({
    name: String
}, {capped: 100});

const passSchema = new mongoose.Schema({
    name: String,
}, {capped: {size: 100}})

async function run() {
    await mongoose.connect('mongodb://localhost:27017');
    await mongoose.connection.dropDatabase();
    await mongoose.model('thing', failSchema).createCollection();
}

run();

@IslandRhythms IslandRhythms added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Mar 17, 2022
@vkarpov15 vkarpov15 added this to the 6.2.12 milestone Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

3 participants