0

我在玩 MongoDB 和 Twitter。我已经在 mongo 中存储了推文。具有以下结构:

{
  "_id": { "$oid" : "520f9d002fcd932d25671186" },
  "contributors": null,
  "truncated": false,
  "text": "@usasoccerguy  #TweetYourEPLParty http://t.co/s1itZDWp6d",
  "in_reply_to_status_id": null,
  "id": 368762912623452160,
  "favorite_count": 0,
  "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
  "retweeted": true,
  "coordinates": {
    "type": "Point",
    "coordinates": [
      -73.740783609999994042,
      40.939503680000001395
    ]
  },
  "entities": {
    "symbols": [

    ],
    "user_mentions": [
      {
        "id": 1249836458,
        "indices": [
          0,
          13
        ],
        "id_str": "1249836458",
        "screen_name": "usasoccerguy",
        "name": "Soccer Guy"
      }
    ],
    "hashtags": [
      {
        "indices": [
          15,
          33
        ],
        "text": "TweetYourEPLParty"
      }
    ],
    "urls": [

    ],
    "media": [
      {
        "expanded_url": "http://twitter.com/JamesJMaybury/status/368762912623452160/photo/1",
        "display_url": "pic.twitter.com/s1itZDWp6d",
        "url": "http://t.co/s1itZDWp6d",
        "media_url_https": "https://pbs.twimg.com/media/BR4b6k3CYAAuZJS.jpg",
        "id_str": "368762912631840768",
        "sizes": {
          "large": {
            "h": 768,
            "resize": "fit",
            "w": 1024
          },
          "small": {
            "h": 255,
            "resize": "fit",
            "w": 340
          },
          "medium": {
            "h": 450,
            "resize": "fit",
            "w": 600
          },
          "thumb": {
            "h": 150,
            "resize": "crop",
            "w": 150
          }
        },
        "indices": [
          34,
          56
        ],
        "type": "photo",
        "id": 368762912631840768,
        "media_url": "http://pbs.twimg.com/media/BR4b6k3CYAAuZJS.jpg"
      }
    ]
  },
  "in_reply_to_screen_name": "usasoccerguy",
  "id_str": "368762912623452160",
  "retweet_count": 0,
  "in_reply_to_user_id": 1249836458,
  "favorited": false,
  "user": {
    "follow_request_sent": null,
    "profile_use_background_image": true,
    "default_profile_image": false,
    "id": 73135664,
    "verified": false,
    "profile_image_url_https": "https://si0.twimg.com/profile_images/2656459048/47bbb326153fef0252bd3b2bc31a128e_normal.jpeg",
    "profile_sidebar_fill_color": "E3E2DE",
    "profile_text_color": "634047",
    "followers_count": 186,
    "profile_sidebar_border_color": "D3D2CF",
    "id_str": "73135664",
    "profile_background_color": "EDECE9",
    "listed_count": 5,
    "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme3/bg.gif",
    "utc_offset": 3600,
    "statuses_count": 681,
    "description": "Middle aged grump, loves Spurs and eating, not much else",
    "friends_count": 648,
    "location": "London, England",
    "profile_link_color": "088253",
    "profile_image_url": "http://a0.twimg.com/profile_images/2656459048/47bbb326153fef0252bd3b2bc31a128e_normal.jpeg",
    "following": null,
    "geo_enabled": true,
    "profile_banner_url": "https://pbs.twimg.com/profile_banners/73135664/1352919217",
    "profile_background_image_url": "http://a0.twimg.com/images/themes/theme3/bg.gif",
    "name": "James Maybury",
    "lang": "en",
    "profile_background_tile": false,
    "favourites_count": 12,
    "screen_name": "JamesJMaybury",
    "notifications": null,
    "url": null,
    "created_at": "Thu Sep 10 15:02:59 +0000 2009",
    "contributors_enabled": false,
    "time_zone": "London",
    "protected": false,
    "default_profile": false,
    "is_translator": false
  },
  "geo": {
    "type": "Point",
    "coordinates": [
      40.939503680000001395,
      -73.740783609999994042
    ]
  },
  "in_reply_to_user_id_str": "1249836458",
  "possibly_sensitive": false,
  "lang": "vi",
  "created_at": "Sat Aug 17 15:55:04 +0000 2013",
  "filter_level": "medium",
  "in_reply_to_status_id_str": null,
  "place": {
    "full_name": "Mamaroneck, NY",
    "url": "https://api.twitter.com/1.1/geo/id/e9358cb13da67394.json",
    "country": "United States",
    "place_type": "city",
    "bounding_box": {
      "type": "Polygon",
      "coordinates": [
        [
          [
            -73.763955999999993196,
            40.889043999999998391
          ],
          [
            -73.763955999999993196,
            40.969379000000003543
          ],
          [
            -73.70957400000000348,
            40.969379000000003543
          ],
          [
            -73.70957400000000348,
            40.889043999999998391
          ]
        ]
      ]
    },
    "country_code": "US",
    "attributes": {

    },
    "id": "e9358cb13da67394",
    "name": "Mamaroneck"
  }
}

现在我想找到所有被转发的推文,所以在哪里转发:是的,但我不明白我是怎么做到的。我试过了,db.twitter.tweets.find({"_id": { "retweeted": "true" }})但这没有用。有人能帮助我吗?

4

1 回答 1

2

删除_id查询对象的一部分和引号,"true"以便将其视为布尔值而不是字符串:

db.twitter.tweets.find({ retweeted: true })

要匹配user/等嵌入字段location,您需要使用点表示法:

db.twitter.tweets.find({ 'user.location': 'London, England' })

find可以在这里找到很好的查询概述。

于 2013-09-06T12:56:25.793 回答