我正在尝试使用 pymongo。到目前为止一切正常,我可以连接到 mongodb,插入和进行查询。我面临的问题是将数据从find()
python 数组中获取。
这是我的代码
>>> a = db.sensor.find({'sensor_id':3})
>>> a
<pymongo.cursor.Cursor object at 0x637f70>
>>> for bla in a:
... print bla
...
{u'date': datetime.datetime(2013, 3, 4, 21, 8, 23, 907000), u'_id': ObjectId('51350d4772ab8a691c370453'), u'sensor_id': 3, u'value': -1625.0}
{u'date': datetime.datetime(2013, 3, 4, 21, 20, 12, 694000), u'_id': ObjectId('5135100c72ab8a695b54a4f3'), u'sensor_id': 3, u'value': -1875.0}
{u'date': datetime.datetime(2013, 3, 4, 21, 22, 4, 985000), u'_id': ObjectId('5135107c72ab8a69851a5a95'), u'sensor_id': 3, u'value': -1812.0}
{u'date': datetime.datetime(2013, 3, 4, 21, 26, 11, 758000), u'_id': ObjectId('5135117372ab8a69b285b4c7'), u'sensor_id': 3, u'value': -1312.0}
有没有办法制作类似的东西myValues[i] = bla.value
?