Skip to content

Instantly share code, notes, and snippets.

@werkshy
Created June 6, 2012 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save werkshy/2885383 to your computer and use it in GitHub Desktop.
Save werkshy/2885383 to your computer and use it in GitHub Desktop.
#### Pymongo 2.1.1
for uuid in list(uuids)[:1]:
query = {
"uuid" : uuid,
}
fields = {"period" : 1, "logs.hour": 1}
for doc in db.logEventByHour.find({"uuid":uuid}, fields=fields):
log.debug("doc: %r", doc)
#### Python output (empty log subdocuments)
doc: {u'_id': ObjectId('XXXXXXXXXXXXXXXXXXXXXXXXX'), u'logs': [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}], u'period': u'2012060622'}
doc: {u'_id': ObjectId('XXXXXXXXXXXXXXXXXXXXXXXXX'), u'logs': [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}], u'period': u'2012060621'}
#### Mongo 2.0.6
db.logEventByHour.find({}, {"logs.hour":1})
#### Shell output (log.hour is present
{ "_id" : ObjectId("XXXXXXXXXXXXXXXXXXXXX"), "logs" : [ { "hour" : 15 }, { "hour" : 15 }, { "hour" : 15 }, { "hour" : 15 }, { "hour" : 15 } ] }
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment