I'm using node js and while searching for a field it takes over 1 minute or more to get the data back is there any solutions to increase performance and make it faster
here is my code:
router.get('/employee', (req,res) => {
let searchQuery = {name: req.query.name};
Employee.findOne(searchQuery)
.then(employee => {
res.render('search',{employee:employee});
})
.catch(err => {
req.flash('error_msg', 'ERROR: '+err)
res.redirect('/');
})
});
Schema:
const mongoose = require('mongoose');
let employeeScheme = new mongoose.Schema({
name: String,
postion: String,
salary: String
});
module.exports = mongoose.model('Employee', employeeScheme);
Yeap. You can create an index for fields you normally search for.
Exemple:
employeeScheme.index({ name: 1, type: 1 })
Read the documentation for choose the best index type for you. https://mongoosejs.com/docs/guide.html#indexes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.