簡體   English   中英

mongodb find上的性能非常慢

[英]Very slow performance on mongodb find

我是nodejs和mongodb的新手。 為了進行測試,我從#oscars中捕獲了2.500.000條推文。 現在,我正在處理數據,但是下面的查詢非常慢……(最多40秒)(我直接在控制台上進行查詢)

db.oscars.find({user.screen_name: "monxas"})

難道我做錯了什么? 無論如何有加速這個查詢?

推文具有這種結構,如果有幫助的話:

 {
  "_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"
}

使用explain游標方法查找有關查詢計划的更多信息

db.oscars.find({user.screen_name: "monxas"}).explain();

如果沒有定義索引,則可以在user.screen_name上添加一個user.screen_name以使用ensureIndex加快查詢速度,如下所示

db.oscars.ensureIndex({"user.screen_name": 1});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM