Skip to content

Instantly share code, notes, and snippets.

@xianminx
Created August 4, 2015 18:26
Show Gist options
  • Select an option

  • Save xianminx/0e4f73d435d6dcdc7bcb to your computer and use it in GitHub Desktop.

Select an option

Save xianminx/0e4f73d435d6dcdc7bcb to your computer and use it in GitHub Desktop.

下面的数据, 我如何进行这样的查询: "_id": ObjectId("55b1ea877717d27b05fd3782"), 返回title abstract 以及statements 中 "_id": ObjectId("55b1eae87717d29e05fd3785"),的数据

{
  "_id": ObjectId("55b1ea877717d27b05fd3782"),
  "title": "喷气背包是怎样从科幻小说一步步走向现实的。",
  "abstract": "这个星球最酷的飞行器都在这里了!",
  "source": "http://official.baijia.baidu.com/article/89679",
  "created_at": ISODate("2015-07-24T07:34:31.474Z"),
  "created_by": ObjectId("55ae460604b06fbe8c4299a6"),
  "host_id": ObjectId("55ae460604b06fbe8c4299a6"),
  "img": {
    "origin": "/public/upload/9674fcf8943e51c49e4f9af37c7f020b.jpg",
    "small": "/public/upload/9674fcf8943e51c49e4f9af37c7f020b.jpg",
    "large": "/public/upload/9674fcf8943e51c49e4f9af37c7f020b.jpg"
  },
  "total_count": 3,
  "statements": [
    {
      "_id": ObjectId("55b1eae87717d28405fd3784"),
      "img": {
        "origin": "/public/upload/9674fcf8943e51c49e4f9af37c7f020b.jpg",
        "small": "/public/upload/9674fcf8943e51c49e4f9af37c7f020b.jpg",
        "large": "/public/upload/9674fcf8943e51c49e4f9af37c7f020b.jpg"
      },
      "vote_up": 0,
      "vote_down": 0,
      "created_at": ISODate("2015-07-24T07:36:08.539Z"),
      "user_id": ObjectId("55ae460604b06fbe8c4299a6")
    },
    {
      "_id": ObjectId("55b1eae87717d29e05fd3785"),
      "content": "喷气背包是怎样从科幻小说一步步走向现实的。",
      "vote_up": 0,
      "vote_down": 0,
      "created_at": ISODate("2015-07-24T07:36:08.845Z"),
      "user_id": ObjectId("55ae460604b06fbe8c4299a6")
    },
    {
      "_id": ObjectId("55be501c2baa09300336f04a"),
      "content": "喷气背包是怎样从科幻小说一步步走向现实的。",
      "vote_up": 0,
      "vote_down": 0,
      "created_at": ISODate("2015-08-02T17:15:08.008Z"),
      "user_id": ObjectId("55ae460604b06fbe8c4299a6")
    }
  ],
  "status": 0,
  "apply_guests": [
    {
      "_id": ObjectId("55be5b16f0633b4e9687dab1"),
      "status": 0,
      "reason": "I want to join you"
    },
    {
      "_id": ObjectId("55be5b16f0633b4e9687dab1"),
      "status": 0,
      "reason": "I want to joinfff you"
    },
    {
      "_id": ObjectId("55be5b16f0633b4e9687dab1"),
      "status": 0,
      "reason": null
    },
    {
      "_id": ObjectId("55be5b16f0633b4e9687dab1"),
      "status": 1,
      "reason": null
    }
  ],
  "guests": [
    ObjectId("55be5b16f0633b4e9687dab1")
  ],
  "auto_join": true
}

希望返回的结果为:

{
  "_id": ObjectId("55b1ea877717d27b05fd3782"),
  "title": "喷气背包是怎样从科幻小说一步步走向现实的。",
  "abstract": "这个星球最酷的飞行器都在这里了!",
  "source": "http://official.baijia.baidu.com/article/89679",
  "statements": [
    {
      "_id": ObjectId("55b1eae87717d29e05fd3785"),
      "content": "喷气背包是怎样从科幻小说一步步走向现实的。",
      "vote_up": 0,
      "vote_down": 0,
      "created_at": ISODate("2015-07-24T07:36:08.845Z"),
      "user_id": ObjectId("55ae460604b06fbe8c4299a6")
    }
}

如果statements 中没有匹配的元素, 不返回 statements内容, 或者可以 statements:[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment