bad JSON array format - found no opening bracket

本文涉及的产品
云数据库 MongoDB,通用型 2核4GB
简介:   我真的不想吐槽mongodb,也可能是刚接触mongodb不久,mongodb数据库真的不是像传说中说的那么好上手。今天有个需求,需要从远程库导出json格式的数据文件,然后导入到另一个远程库。
  我真的不想吐槽mongodb,也可能是刚接触mongodb不久,mongodb数据库真的不是像传说中说的那么好上手。今天有个需求,需要从远程库导出json格式的数据文件,然后导入到另一个远程库。
当完事具备后,执行导入命令的时候,报了错。
 相关数据库服务器信息:
  源库操作系统:windows server 2008R2
 数据库版本:mongodb 3.2.7
 导出工具:mongoChef 3.6.0
 目标端操作系统:LINUX redhat6.4
 数据库版本:mongodb 3.2.7
 导入工具:1、 mongoChef 3.6.0 ;2、mongoimport
 导出与导入数据文件格式:systemprofile.json
 首先,在使用mongoChef进行导入时,报错如图:

真的能让人闹心死,mongoChef能将数据导出,竟然导入不进去,想不通。
 其次,尝试
mongoimport导入,最终是能导入,但是碰到了2次错误。
成功导入方法记录如下:
[mongo@se122 ~]$ mongoimport --db zl --collection systemprofile --port 27000 --file /home/mongo/systemprofile.json  --type json
2016-07-06T09:15:41.377+0800 connected to: localhost:27000
2016-07-06T09:15:42.540+0800 imported 682 documents
[mongo@se122 ~]$
碰到的2次错误:
报错一
[mongo@se122 ~]$ mongoimport --db zl --collection systemprofile --file /home/mongo/systemprofile.json  --jsonArray
2016-07-06T09:04:24.903+0800 [........................] zl.systemprofile 0.0 B/2.0 MB (0.0%)
2016-07-06T09:04:25.407+0800 [........................] zl.systemprofile 0.0 B/2.0 MB (0.0%)
2016-07-06T09:04:25.407+0800 Failed: error connecting to db server: no reachable servers
2016-07-06T09:04:25.407+0800 imported 0 documents
[mongo@se122 ~]$
这个报错好理解,就是 mongoimport无法正常连接到zl数据库,如果mongodb启动使用的不是默认的27017,则需要指定数据库监听的端口号。看来,这方面mongo没有oracle智能。
报错二
[mongo@se122 ~]$ mongoimport --db zl --collection systemprofile --port 27000 --file /home/mongo/systemprofile.json  --jsonArray
2016-07-06T09:05:30.381+0800 connected to: localhost:27000
2016-07-06T09:05:30.382+0800 Failed: error reading separator after document #1: bad JSON array format - found no opening bracket '[' in input source
2016-07-06T09:05:30.383+0800 imported 0 documents
[mongo@se122 ~]$
指定了端口号, mongoimport能连接到zl数据库了,但是又来个bad JSON array format - found no opening bracket '[' in input source
原因是数据格式指定的问题,需要将--jsonArray换成--type json。
使用修改后的命令mongoimport --db zl --collection systemprofile --port 27000 --file /home/mongo/systemprofile.json  --type json就能将数据成功导入了。
[mongo@se122 ~]$ mongoimport --db zl --collection systemprofile --port 27000 --file /home/mongo/systemprofile.json  --type json
2016-07-06T09:15:41.377+0800 connected to: localhost:27000
2016-07-06T09:15:42.540+0800 imported 682 documents
[mongo@se122 ~]$

相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
6月前
|
资源调度 JavaScript Windows
yarn install命令报错解决办法-warning package-lock.json found.
yarn install命令报错解决办法-warning package-lock.json found.
108 0
|
SQL JSON 数据格式
SQL老司机,在SQL中计算 array & map & json数据
场景 通常,我们处理数据,一列数据类型要么是字符串,要么是数字,这些都是primitive类型的数据。在某些比较复杂的业务场景下,我们会在一列中使用复杂的格式,例如数组array, 对象(map),json等格式来表示复杂的数据,例如: __source__: 11.
9763 0
|
2月前
|
JSON 数据格式 C++
C++ JSON库 nlohmann::basic_json::array 的用法
C++ JSON库 nlohmann::basic_json::array 的用法
49 1
|
6月前
|
JSON 监控 数据格式
Grafana导入 json 文件的 dashboard 错误 Templating Failed to upgrade legacy queries Datasource xxx not found
Grafana导入 json 文件的 dashboard 错误 Templating Failed to upgrade legacy queries Datasource xxx not found
141 0
|
3月前
|
SQL 消息中间件 Java
Flink报错问题之使用debezium-json format报错如何解决
Apache Flink是由Apache软件基金会开发的开源流处理框架,其核心是用Java和Scala编写的分布式流数据流引擎。本合集提供有关Apache Flink相关技术、使用技巧和最佳实践的资源。
|
3月前
|
SQL Java 关系型数据库
flink问题之使用debezium-json format报错如何解决
Apache Flink是由Apache软件基金会开发的开源流处理框架,其核心是用Java和Scala编写的分布式流数据流引擎。本合集提供有关Apache Flink相关技术、使用技巧和最佳实践的资源。
54 0
|
12月前
|
JSON JavaScript 数据格式
js array数组json去重
js array数组json去重
106 0
|
JSON PHP 数据库
PHP:Laravel cast array json数据存数据库时unicode 编码问题和update更新不触发数据转换
PHP:Laravel cast array json数据存数据库时unicode 编码问题和update更新不触发数据转换
106 0
|
JSON 前端开发 数据格式
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `object` out of START_ARRAY token
讲述如何处理 org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `object` out of START_ARRAY token的问题
 org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `object` out of START_ARRAY token
|
SQL 消息中间件 JSON
Flink SQL JSON Format 源码解析
用 Flink SQL 解析 JSON 格式的数据是非常简单的,只需要在 DDL 语句中设置 Format 为 json 即可,像下面这样: CREATE TABLE kafka_source ( funcName STRING, data ROW<snapshots ARRAY<ROW<content_type STRING,url STRING>>,audio ARRAY<ROW<content_type STRING,url STRING>>>, resultMap ROW<`result` MAP<STRING,STRING>,isSuccess BOOLEAN