首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mongodb查找的性能非常慢

mongodb查找的性能非常慢
EN

Stack Overflow用户
提问于 2015-02-26 14:57:27
回答 1查看 1.7K关注 0票数 0

我是nodejs和mongodb的新手。为了验证这一点,我从#奥斯卡网站上获得了2.50万条推文。现在我正在处理数据,但是像下面这样的查询非常慢.(最多40秒)(我直接在控制台上执行查询)

代码语言:javascript
复制
db.oscars.find({user.screen_name: "monxas"})

我做错了什么吗?是否存在加速查询的方法?

tweets具有这种结构,如果这有帮助的话:

代码语言:javascript
复制
 {
  "_id" : ObjectId("54ea1f0f5fbae7a02067024b"),
  "created_at" : "Sun Feb 22 18:25:20 +0000 2015",
  "id" : 5.6956360590721434E+17,
  "id_str" : "569563605907214338",
  "text" : "#Oscars2015 Who will win tonight? All hopes are on you guys.",
  "source" : "<a href=\"http://twitter.com/#!/download/ipad\" rel=\"nofollow\">Twitter for iPad</a>",
  "truncated" : false,
  "in_reply_to_status_id" : null,
  "in_reply_to_status_id_str" : null,
  "in_reply_to_user_id" : null,
  "in_reply_to_user_id_str" : null,
  "in_reply_to_screen_name" : null,
  "user" : {
    "id" : 2596742425.0,
    "id_str" : "2596742425",
    "name" : "jclivesforever26",
    "screen_name" : "jacuasay092600",
    "location" : "",
    "url" : null,
    "description" : "Da Bulls!!! Ed Sheeran is life!!!",
    "protected" : false,
    "verified" : false,
    "followers_count" : 21,
    "friends_count" : 183,
    "listed_count" : 0,
    "favourites_count" : 78,
    "statuses_count" : 283,
    "created_at" : "Mon Jun 30 18:13:13 +0000 2014",
    "utc_offset" : null,
    "time_zone" : null,
    "geo_enabled" : true,
    "lang" : "en",
    "contributors_enabled" : false,
    "is_translator" : false,
    "profile_background_color" : "C0DEED",
    "profile_background_image_url" : "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_image_url_https" : "https://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_tile" : false,
    "profile_link_color" : "0084B4",
    "profile_sidebar_border_color" : "C0DEED",
    "profile_sidebar_fill_color" : "DDEEF6",
    "profile_text_color" : "333333",
    "profile_use_background_image" : true,
    "profile_image_url" : "http://pbs.twimg.com/profile_images/542805253952135168/Ttwm541P_normal.jpeg",
    "profile_image_url_https" : "https://pbs.twimg.com/profile_images/542805253952135168/Ttwm541P_normal.jpeg",
    "profile_banner_url" : "https://pbs.twimg.com/profile_banners/2596742425/1421468064",
    "default_profile" : true,
    "default_profile_image" : false,
    "following" : null,
    "follow_request_sent" : null,
    "notifications" : null
  },
  "geo" : null,
  "coordinates" : null,
  "place" : null,
  "contributors" : null,
  "retweet_count" : 0,
  "favorite_count" : 0,
  "entities" : {
    "hashtags" : [{
        "text" : "Oscars2015",
        "indices" : [0, 11]
      }],
    "trends" : [],
    "urls" : [],
    "user_mentions" : [],
    "symbols" : []
  },
  "favorited" : false,
  "retweeted" : false,
  "possibly_sensitive" : false,
  "filter_level" : "low",
  "lang" : "en",
  "timestamp_ms" : "1424629520285"
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-26 15:08:23

使用explain游标方法查找有关查询计划的更多信息

代码语言:javascript
复制
db.oscars.find({user.screen_name: "monxas"}).explain();

如果没有定义索引,则可以在user.screen_name上添加索引,以使用ensureIndex加快查询速度,如下所示

代码语言:javascript
复制
db.oscars.ensureIndex({"user.screen_name": 1});
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28745630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档