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

why mongoose version 5 is so slow ? #7596

Closed
Zoha opened this issue Mar 10, 2019 · 2 comments
Closed

why mongoose version 5 is so slow ? #7596

Zoha opened this issue Mar 10, 2019 · 2 comments

Comments

@Zoha
Copy link

Zoha commented Mar 10, 2019

Hi.
I started a normal project and install mongoose.
the version that was installed is 5.4.18
after creating some models ] wanted to test models with mocha .
and ] figure out that mongoose queries are too slow .
each query takes about 1 - 2 second to execute!!
I understood that if I switch to previous versions like 4.4.10 queries will work properly.
this is my simple code for test speed :

const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
mongoose.connect("mongodb://localhost:27017/testdb");

let User  = mongoose.model('User', new mongoose.Schema({
    username: {
        type: String,
        required: false,
        default: '',
        min: 0,
        max: 255,
    },
    email: {
        type: String,
    }
}));

let user = new User({
    username: 'test',
    email: 'tesafdjklas@gmail.com',
});

let time = (new Date).getTime();
user.save().then(() => {
    console.log('OK :' + ((new Date).getTime() - time));
});

after execute with mongoose version 5.4.18 it prints OK :1004 -> about 1 seconds to execute
but by version 4.4.10 it prints OK :40 -> 40 ms
So . why new version is too slow ?
or if I'm doing something wrong, what is it ?

@Zoha
Copy link
Author

Zoha commented Mar 10, 2019

I replaced :
mongoose.connect("mongodb://localhost:27017/testdb");
with :
mongoose.connect("mongodb://127.0.0.1:27017/testdb");
and it is ok now :)

@Zoha Zoha closed this as completed Mar 10, 2019
@vkarpov15
Copy link
Collaborator

ipv4 vs ipv6: See: https://mongoosejs.com/docs/connections.html#options .

@Automattic Automattic locked as resolved and limited conversation to collaborators Mar 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants