在 MongoDB 中导入 json 文件时出现“EOF”错误

时间:2021-03-30 21:53:38

标签: json mongodb

我正在尝试使用 Compass 将 the following json file 导入 MongoDB,但出现错误:

Unexpected token � in JSON at position 0 while parsing near '�' in C:\Users\antoi\Downloads\restaurants.json 

> 1 | �
| ^

然后我尝试从另一个来源对其进行测试,但没有奏效:

Error: Parse error on line 10:
...s Park Bake Shop"} { "_id": {        "$oid"
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'

是否缺少引号?但是当我添加引号时,它给了我:

Error: Parse error on line 10:
...is Park Bake Shop"}, {   "_id": {        "$oi
----------------------^
Expecting 'EOF', got ','

1 个答案:

答案 0 :(得分:1)

使用mongoimport

mongoimport --db myDb --collection restaurants --file restaurants.json
<块引用>

restaurants.json 不是有效的 JSON,未包装在数组中,末尾也没有逗号。

https://docs.mongodb.com/manual/reference/mongodb-extended-json/

相关问题