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

Limit isn't applied when a string is informed #11017

Closed
wesleimarinho opened this issue Nov 26, 2021 · 3 comments
Closed

Limit isn't applied when a string is informed #11017

wesleimarinho opened this issue Nov 26, 2021 · 3 comments
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@wesleimarinho
Copy link

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

What is the current behavior?
If I use {limit:'2'} or limit('2') the option isn't apllied (or a variable with string value instead of Number).

Is this the exptected behavior?

There is no information about this on https://mongoosejs.com/docs/api/query.html#query_Query-limit, despite mentioning it is expected a number.

@wesleimarinho wesleimarinho changed the title Limit isn't applyied when a string is informed Limit isn't applied when a string is informed Nov 26, 2021
@IslandRhythms IslandRhythms added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label Nov 29, 2021
@IslandRhythms
Copy link
Collaborator

Works fine for me

const mongoose = require('mongoose');
const {Schema} = mongoose;

const testSchema = new Schema({
    file: Number
});

const Test = mongoose.model('Test', testSchema);

async function run() {
    await mongoose.connect('mongodb://localhost:27017/', {useNewUrlParser: true,
    useUnifiedTopology: true,});
    await mongoose.connection.dropDatabase();

    for (let i = 0; i < 20; i++) {
        await Test.create({file: i});
    }

    console.log(await Test.find().limit(5));
    console.log(await Test.find({},null,{limit: 5}));
}

run();

@wesleimarinho
Copy link
Author

Proper test case, according to the issue description is:

const mongoose = require('mongoose');
const {Schema} = mongoose;

const testSchema = new Schema({
    file: Number
});

const Test = mongoose.model('Test', testSchema);

async function run() {
    await mongoose.connect('mongodb://localhost:27017/', {useNewUrlParser: true,
    useUnifiedTopology: true,});
    await mongoose.connection.dropDatabase();

    for (let i = 0; i < 20; i++) {
        await Test.create({file: i});
    }

    console.log(await Test.find().limit(String.valueOf(5)));
    console.log(await Test.find({},null,{limit: '5'}));
}

run();

@IslandRhythms IslandRhythms added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary and removed can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. labels Nov 30, 2021
@IslandRhythms
Copy link
Collaborator

It expects a number, so putting a string is an improper use.

@vkarpov15 vkarpov15 added this to the 6.0.17 milestone Dec 5, 2021
@vkarpov15 vkarpov15 modified the milestones: 6.1.4, 6.1.6 Dec 15, 2021
@vkarpov15 vkarpov15 modified the milestones: 6.1.6, 6.1.5 Jan 4, 2022
@vkarpov15 vkarpov15 added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature and removed help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

No branches or pull requests

3 participants