2015-11-27 27 views
0

我在此語法中使用了Mongo集合。如何將每個文件導出到包含數組的文本文件中?使用javascript將mongo集合中的所有數據轉換爲文本文件

{ 
     _id: 1, 
     "author": [ 
     { 
      "fname": "Petr", 
      "lname": "Kocircurka" 
     } 
     ], 
     "title": "On topological dynamics of Turing machines", 
     "journal": "Theor. Comput. Sci.", 
     "volume": "174", 
     "pages": [ 
     { 
      "FirstNumber": "203", 
      "LastNumber": "216" 
     } 
     ], 
     "year": "1997", 
     "url": "http://www.sciencedirect.com/science/journal/03043975/" 
    }{ 
     _id: 2, 
     "author": [ 
     { 
      "fname": "Aviezri", 
      "lname": "Fraenkel" 
     }, 
     { 
      "fname": "Jamie", 
      "lname": "Simpson" 
     } 
     ], 
     "title": "The exact number of squares in Fibonacci words", 
     "journal": "Theor. Comput. Sci.", 
     "volume": "218", 
     "pages": [ 
     { 
      "FirstNumber": "95", 
      "LastNumber": "106" 
     } 
     ], 
     "year": "1999", 
     "url": "http://www.sciencedirect.com/science/journal/03043975/" 
    } 

感謝

+0

您是否嘗試過'mongoexport'效用? https://docs.mongodb.org/manual/reference/program/mongoexport/我知道它適用於CSV和JSON。不確定它是否解決了您的特定需求。 – Sergio

+0

是的,我有它不導出數組,也嘗試把./mongoexport – Abiwax

+0

你可以發佈你用於導出集合及其輸出的命令? – codenut

回答

0
mongoexport --db yourDbName --collection collectionName --out fileName.json -u userName -p yourPassword 
+1

想[解釋你的解決方案](http://stackoverflow.com/help/how-to-answer)有點? –

+0

它必須在文本文件中,並且mongo集合包含數組,它應該作爲字段導出到文本文件中。 – Abiwax

+0

這裏將yourDbName - >替換爲您自己的數據庫名稱filename.json->替換您想要導出的文件的位置,並且如果您擁有數據庫的憑據,請在userName和yourPassword的位置上使用您的憑據,否則不要使用「 t包含這些憑證。簡單地使用mongoexport --db yourDbName --collection collectionName --out fileName.json –

相關問題