一、导出工具mongoexport mongoexport --help
Mongodb中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件。可以通过参数指定导出的数据项,也可以根据指定的条件导出数据。mongoexport具体用法如下所示:
参数说明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-f:指明要导出那些列
-o:指明到要导出的文件名
-q:指明导出数据的过滤条件
eg:mongoexport -d test -c students -o students.dat
eg:mongoexport -d test -c students --csv -f classid,name,age -o students_csv.dat
二、导入工具mongoimport mongoimport --help
Mongodb中的mongoimport工具可以把一个特定格式文件中的内容导入到指定的collection中。该工具可以导入JSON格式数据,也可以导入CSV格式数据。具体使用如下所示:
参数说明:
-h:指明数据库宿主机的IP
-u:指明数据库的用户名
-p:指明数据库的密码
-d:指明数据库的名字
-c:指明collection的名字
-f:指明要导入那些列
eg:mongoimport -d test -c students --type csv --headerline --file students_csv.dat
-type:指明要导入的文件格式
-headerline:指明第一行是列名,不需要导入
-file:指明要导入的文件
三、启动mongo
mongd -f 配置文件路径(/etc/mongod.cof)
mongo删除某个字段:db.CompanyName.update({},{$unset:{‘flag’:’’}},false, true)