从文件中获取jsons对象,并使用nodeJS中的mongoose插入MongoDB

时间:2017-04-03 15:40:07

标签: json node.js mongodb mongoose

我有一个文件“rooms.json”:

{ "name": "Computer science class 1" , "location": "Mid School upper floor"}
{ "name": "Computer science class 2" , "location": "Mid School upper floor"}
{ "name": "Computer science class 3" , "location": "Mid School upper floor"}
{ "name": "classG12N1" , "location": "High School building upper floor"}
{ "name": "classG12N2" , "location": "High School building upper floor"}
{ "name": "classG12N3" , "location": "High School building upper floor"}
{ "name": "classG12N4" , "location": "High School building upper floor"}
{ "name": "classG11N1" , "location": "High School building lower floor"}
{ "name": "classG11N2" , "location": "High School building lower floor"}
{ "name": "classG11N3" , "location": "High School building lower floor"}

我在nodeJS中使用mongoose。我需要一个函数来读取文件,在json中格式化并插入数据库。

我已经尝试逐行读取文件并自行解析,但它根本没有效率。还有其他办法吗?

PS,我在网上搜索了一些解决方案,但还没找到。

0 个答案:

没有答案