下面是JSON:
"work": {
"secondary_sku": [],
"internal_work": [
{
"name": "NCB",
"LOB": "RUNME",
"rm": "prabhu",
"skills": [
"python",
"javascript libraries",
"java applets",
"py",
"sqoop"
],
"role": ObjectId("589c6da731beda27110af128"),
"description": "Strong understanding of JavaScript, its quirks, and workarounds\n\nBasic understanding of web markup, including HTML5- and CSS3\n\nGood understanding of advanced JavaScript libraries and frameworks such as: AngularJS, KnockoutJS, Backbone.js, ReactJS, DurandalJS, Vue.js etc.\n\nGood understanding of asynchronous request handling- and partial page updates\n\nKnowledge of advanced JavaScript Concepts like Closures,- Promises- and Callbacks",
"responsibility": "Strong understanding of JavaScript, its quirks, and workarounds\n\nBasic understanding of web markup, including HTML5- and CSS3\n\nGood understanding of advanced JavaScript libraries and frameworks su- ch as: AngularJS, KnockoutJS, Backbone.js, ReactJS, DurandalJS, Vue.js etc.\n\nGood understanding of asynchronous request handling- and partial page updates\n\nKnowledge of advanced JavaScript Concepts like Closures,- Promises- and Callbacks",
"current": false,
"start": ISODate("2017-03-30T00:00:00.000Z"),
"end": ISODate("2017-03-31T00:00:00.000Z"),
"billable": false,
"client": "test"
}
]
}
如何从mongodb中读取“工作”细节数据。我试着这样做:
work = [nref.get('internal_work', '') for nref in details.get('work', [{}])]
和
work = details["work"].get("internal_work","")
注意:details
是循环变量的名称。
3条答案
按热度按时间eqoofvh91#
我不太明白你的问题,因为你的Json样本格式不正确。提供有关唯一ID、集合名称和数据库名称的详细信息。无论如何,如果你使用Pyhon,我推荐使用PyMongo驱动程序。
使用PyMongo,搜索代码看起来像这样...
查询(find)将取决于Json的正确结构。
有关如何使用Pymongo的更多信息,请使用此link。问候
fnvucqvd2#
使用pymongo从mongodb读取数据
f3temu5u3#
在2023年回答这个问题,所以我使用Python3从
employees
数据库中的details
这样的记录集合中读取work
中显示的具有上述结构的记录:如果你仍然需要在Python 2.7中找到答案,请注意PyMongo 3.12.0有deprecated support for 2.7,所以请确保你使用的版本不是比这个版本更新。