2017-10-25 11 views
0

は、JSONです:Pythonを使ってmongodbからデータを読み込むには?ここ

"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 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", 
       "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', [{}])] 

仕事=詳細[ "仕事"]( "internal_workを"、 "")を取得

注: "私はこのような試みた 詳細は" の名前でありますループ変数。

答えて

0

Json youのサンプルのフォーマットが正しくないため、あなたの質問がうまく理解できません。一意のID、コレクションおよびデータベースの名前について詳しく説明します。 とにかくPyhonを使用する場合は、PyMongoドライバの使用をお勧めします。

PyMongo、検索コードを使用すると、次のようになります...

from pymongo import MongoClient 
  
def main(): 
      
     # Connection to the MongoDB Server 
     mongoClient = MongoClient ('Your_IP: Your_Port') 
     # Connection to the database 
     db = mongoClient.Your_DataBase 
     #Collection 
     collection = db.Your_Colection 
      
     details = collection.find ({"Work": "id_"}) 
              
if __name__ == "__main__": 
         main() 

問い合わせは(見つける)あなたのJSONの正しい構造に依存します。

Pymongoの使用方法の詳細については、linkを参照してください。 お礼、

関連する問題