1
dreampuf Mar 31, 2013
print json.dump(list(result))
|
2
013231 Mar 31, 2013
json.dumps([dict((key, item[key]) for key in item if key != '_id') for item in doc.find()])
|
3
013231 Mar 31, 2013
上面的答案要修改一下.
json.dumps([dict((key, item[key]) for key in item if key != '_id') for item in result]) |
4
ritksm Mar 31, 2013 亲们。。。要去掉_id直接在find里加参数不就得了。。。find({}, {"_id":0})
|
5
ritksm Mar 31, 2013
建议lz参考document。。。。http://api.mongodb.org/python/2.5/
|
6
hilenlai OP @dreampuf 这个结果不对撒~
@013231 这个可行!!得到一串 [{"age": 25.0, "name": "zhangsan", "sex": 1.0}, {"age": 25.0, "name": "zhangsan", "sex": 1.0}, {"age": 25.0, "name": "zhangsan", "sex": 1.0}, {"age": 25.0, "name": "zhangsan", "sex": 1.0}, {"age": 25.0, "name": "zhangsan", "sex": 1.0}, {"age": 25.0, "name": "zhangsan", "sex": 1.0}, {"age": 25.0, "name": "zhangsan", "sex": 1.0}, {"age": 25.0, "name": "zhangsan", "sex": 1.0}] @ritksm 其实不是去掉id.. mongo查出来的不是bson嘛。 然后我想转化成json :) |
7
binux Mar 31, 2013
|
9
ritksm Mar 31, 2013
@hilenlai bson是mongodb用来存储的格式。。。。pymongo查出来已经是dict了。。。。想知道是什么类型请用type(X)
http://d.pr/i/2cSz BTW:Connection已经在新版本的pymongo中被弃用了。。。用MongoClient吧。。。 |
11
ooscrewyou Apr 9, 2013
@hilenlai 和Python版本沒關係 Connection已經deprecated了
|