mongoexport

Can mongoexport --csv export fields with special characters such as a slash?

蓝咒 提交于 2020-01-07 04:51:13
问题 mongoexport v2.6.4, when used with --csv, seems to ignore fields with slashes in them and emit an incorrect CSV header row: mongoexport ... --csv -f 'id,meta.og/url,meta.twitter/url' outputs the CSV header row id,meta.og The mongo shell has no problem isolating fields with slashes in them. Any ways to work around this without pulling the entire JSON document? 回答1: The solution that worked was to use a field file with the --fieldFile option. 来源: https://stackoverflow.com/questions/29887965/can

mongodb之mongoexport 和mongoimport介绍

好久不见. 提交于 2020-01-05 13:32:17
环境:mongodb3.6.16二进制安装 一、mongoexport 参数和语法介绍: Mongodb中的mongoexport工具可以把一个collection导出成JSON格式或CSV格式的文件。可以通过参数指定导出的数据项,也可以根据指定的条件导出数据。 mongoexport -h IP --port 端口 -u 用户名 -p 密码 -d 数据库 -c 表名 -f 字段 -q 条件导出 --csv -o 文件名 -h 指明数据库宿主机的IP -u 指明数据库的用户名 -p 指明数据库的密码 -d 指明数据库的名字 -c 指明collection的名字 -f 指明要导出那些列,以逗号分割,-f uid,name,age导出uid,name,age这三个字段 -o 指明到要导出的文件名 -q 指明导出数据的过滤条件,-q '{ "uid" : "100" }' 导出uid为100的数据 --type 指定文件类型 --authenticationDatabase 验证数据的名称 导出整张表数据: [root@localhost ~]# mongoexport -h 127.0.0.1:6068 -u root -p TdLLQ6689 --authenticationDatabase admin -d dbtest002 -c mumu -o ./1.dat 2020-01

How to mongoexport and mongoimport collections with new ids but keeping the relation

落花浮王杯 提交于 2019-12-31 03:29:28
问题 I export 2 collections using mongoexport: mongoexport -h -u -p --db dev -c parent -q '{_id: ObjectId("5ae1b4b93b131f57b33b8d11")}' -o parent.json and mongoexport -h -u -p --db dev -c children -q '{parentId: ObjectId("5ae1b4b93b131f57b33b8d11")}' -o children.json From the first one I got one record (selected by ID) and from the second I got many record (selected by parentId which is ID from the first one. How can I use mongoimport to import those with new IDs but keeping the relation -> parent

Mongo导出mongoexport和导入mongoimport介绍

怎甘沉沦 提交于 2019-12-25 18:18:17
一、导出工具mongoexport 简介,通过帮助先了解下mongoexport的功能参数 mongoexport --help Usage: mongoexport <options> Export data from MongoDB in CSV or JSON format. See http://docs.mongodb.org/manual/reference/program/mongoexport/ for more information. general options: --help print usage --version print the tool version and exit verbosity options: -v, --verbose more detailed log output (include multiple times for more verbosity, e.g. -vvvvv) --quiet hide all log output connection options: -h, --host= mongodb host to connect to (setname/host1,host2 for replica sets) --port= server port (can also use --host hostname

MongoDB- backing up and restoring users and roles

我是研究僧i 提交于 2019-12-24 08:07:40
问题 What are best practices for synching users and roles between Mongo instances? On the same Windows machine, I am trying to copy MongoDB users and roles in the admin database from one Mongo instance to another. Authentication is 'on' for each instance. No combination of mongodump\mongorestore or mongoexport\mongoimport I have tried works. With mongodump\restore, the restore step displays: assuming users in the dump directory are from <= 2.4 (auth version 1) Failed: the users and roles

Mongoexport error parsing query

删除回忆录丶 提交于 2019-12-23 11:47:27
问题 Im trying to do a mongoexport to CSV but only selecting certain records with a query. Here's my command (windows 7 cmd): mongoexport --host foo.com --port 27017 --username bar -p --db foo --csv --fields col1,col2,col3 --collection bar --out dump_q.csv --query '{"recent":"yes"}' However after entering the password, I get an error: assertion: 16619 code FailedToParse: FailedToParse: Expecting '{': offset:0 The command works fine without the query argument but I cant figure out whats wrong with

Mongoexport error parsing query

做~自己de王妃 提交于 2019-12-23 11:47:01
问题 Im trying to do a mongoexport to CSV but only selecting certain records with a query. Here's my command (windows 7 cmd): mongoexport --host foo.com --port 27017 --username bar -p --db foo --csv --fields col1,col2,col3 --collection bar --out dump_q.csv --query '{"recent":"yes"}' However after entering the password, I get an error: assertion: 16619 code FailedToParse: FailedToParse: Expecting '{': offset:0 The command works fine without the query argument but I cant figure out whats wrong with

mongoexport aggregate export to a csv file

喜欢而已 提交于 2019-12-20 09:27:43
问题 I want to save the result from an aggregation into a csv file. Using the mongo cmd line tool I can do this to get the results I want: db.compras.aggregate({ $group : { _id : "$data.proponente", total : { $sum : "$price" } }} How would I translate this into a mongoexport command that saves results into a csv? 回答1: You can't run aggregate() queries through mongoexport . The mongoexport tool is intended for more basic data export with a query filter rather than full aggregation and data

mongodb: extract timestamp from ObjectID in json query

有些话、适合烂在心里 提交于 2019-12-19 03:42:13
问题 I want to extract the timestamp from my ObjectID with a json query, as I would like to use mongodump but only dump data between certain dates. I dont wanna put my timestamps somewhere else than the ObjectID as I need the database to be as small as possible. Is there a way to to exstract the timestamp from ObjectID with a simple json query that mongodump accepts? 回答1: You can do this fairly simply, at doc page Mongo Extended JSON (which is quite well hidden) you can find a table describing how

MongoDB - mongoexport all objects in nested array

烈酒焚心 提交于 2019-12-18 05:21:43
问题 I'm using MongoDB version 2.6.x . And I need to export documents from a specific collection. mongoexport is the tool which serves the need. However, I do not know how to export all the objects under a nested array. Below is the sample document I have. { "_id": 1, "field_1": "value1", "field_2": "value2", "field_array": [ {"sub_field_1": "sub_val_1", "sub_field_2": "sub_val_2"}, {"sub_field_1": "sub_val_1", "sub_field_2": "sub_val_2"}, {"sub_field_1": "sub_val_1", "sub_field_2": "sub_val_2"} ]