【问题标题】:How to Speed UP Mongodb Query?如何加快 Mongodb 查询速度?
【发布时间】:2018-07-25 12:25:39
【问题描述】:

我正在使用 Sails Js 和 MongoDB 数据库。我想在Query下面进行优化。

Users.findOne({id:user_id})
    .populate('educations')
    .populate('educations.educationlinks')
    .populate('educations.educationlinks.verify_request_id')
    .populate('educations.educationlinks.verify_request_id.user_id')
.populate('educations.educationlinks.verify_request_id.user_id.company_id')
    .exec(function(err, user){
        return res.json(user);
});

请帮帮我.....

【问题讨论】:

    标签: node.js mongodb sails.js mongoose-populate sails-mongo


    【解决方案1】:

    默认情况下,SailsJS 不对 MongoDB 查询使用区分大小写。 要优化 MongoDB 查询性能,请尝试在 Mongo 查询代码(连接 .js 文件中的 MongoDB 代码)中强制区分大小写:

      wlNext: {
          caseSensitive: true
       }
    
    //For Example:
        someMongodbServer: {
          adapter: 'sails-mongo',
          host: 'localhost',
          port: 27017,
          database: 'sails_demo' //optional
          wlNext: {
              caseSensitive: true
           }
        },
    

    希望这会有所帮助!

    其他资源:

    https://docs.mongodb.com/manual/tutorial/optimize-query-performance-with-indexes-and-projections/

    【讨论】:

    • 感谢您的回复,这个选项我已经申请了,但它不起作用。
    猜你喜欢
    • 2014-10-04
    • 1970-01-01
    • 2012-10-26
    • 2015-04-07
    • 1970-01-01
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多