mongoexport

MongoDB: export distinct column value

余生颓废 提交于 2021-02-07 18:22:32
问题 Anyone have idea how to export distinct column value on mongodb using mongoexport command. Command: db.coll.distinct("uid"); The solution i have tried is : mongoexport --csv -d db -c collection -q '{distinct: "collection", "key": "uid"}' -f "uid" -o distinctUid.csv 回答1: It's not possible to do it this way. distinct is a database command, and --query option allows to use only a query to filter documents. If you are using mongodb v3.4 or later, you can use views to aggregate your collection and

MongoDB: export distinct column value

我与影子孤独终老i 提交于 2021-02-07 18:22:14
问题 Anyone have idea how to export distinct column value on mongodb using mongoexport command. Command: db.coll.distinct("uid"); The solution i have tried is : mongoexport --csv -d db -c collection -q '{distinct: "collection", "key": "uid"}' -f "uid" -o distinctUid.csv 回答1: It's not possible to do it this way. distinct is a database command, and --query option allows to use only a query to filter documents. If you are using mongodb v3.4 or later, you can use views to aggregate your collection and

MongoDB: export distinct column value

眉间皱痕 提交于 2021-02-07 18:22:02
问题 Anyone have idea how to export distinct column value on mongodb using mongoexport command. Command: db.coll.distinct("uid"); The solution i have tried is : mongoexport --csv -d db -c collection -q '{distinct: "collection", "key": "uid"}' -f "uid" -o distinctUid.csv 回答1: It's not possible to do it this way. distinct is a database command, and --query option allows to use only a query to filter documents. If you are using mongodb v3.4 or later, you can use views to aggregate your collection and

how to export mongodb without any wrapping with NumberInt(…)?

青春壹個敷衍的年華 提交于 2021-02-07 07:31:01
问题 I want to export mongodb as json, here is a record: {"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)} the problems is when I use json to loads it: json.loads('{"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)}') it returns ValueError: No JSON object could be decoded . This is because json can not deal with NumberInt(1) . So how can I translate NumberInt(1) to 1 when I export? 回答1: [UPDATE] IF your mongo collection does not include NumberInt,

how to export mongodb without any wrapping with NumberInt(…)?

帅比萌擦擦* 提交于 2021-02-07 07:30:18
问题 I want to export mongodb as json, here is a record: {"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)} the problems is when I use json to loads it: json.loads('{"_id":{"$oid":"554f042c0e81bf483e4a4e2f"}, "batch":"3","bz":NumberInt(1)}') it returns ValueError: No JSON object could be decoded . This is because json can not deal with NumberInt(1) . So how can I translate NumberInt(1) to 1 when I export? 回答1: [UPDATE] IF your mongo collection does not include NumberInt,

Mongoexport to multiple csv files

佐手、 提交于 2020-06-12 09:12:00
问题 I have a large mongoDB collection. I want to export this collection to CSV so I can then import it in a statistics package to do data analysis. The collection has about 15 GB of documents in it. I would like to split the collection into ~100 equally sized CSV files. Is there any way to achieve this using mongoexport? I could also query the whole collection in pymongo, split it and write to csv files manually, but I guess this would be slower and would require more coding. Thank you for input.

MongoDB: Issue when using mongoexport with --query option

夙愿已清 提交于 2020-03-21 04:52:53
问题 When I try to take backup with mongoexport using the --query option to get the documents whose status is equal to A, facing the below error: mongoexport --port 27017 --db ex --collection A --type=csv --fields _id,status --query '{"status":"A"}' -o eg.csv error validating settings: query ''{status:A}'' is not valid JSON Please let me know how to use --query option. 回答1: Assuming you run this from the DOS command prompt, you need to swap the single and double quotes. You need to wrap the entire

MongoDB: Issue when using mongoexport with --query option

懵懂的女人 提交于 2020-03-21 04:52:30
问题 When I try to take backup with mongoexport using the --query option to get the documents whose status is equal to A, facing the below error: mongoexport --port 27017 --db ex --collection A --type=csv --fields _id,status --query '{"status":"A"}' -o eg.csv error validating settings: query ''{status:A}'' is not valid JSON Please let me know how to use --query option. 回答1: Assuming you run this from the DOS command prompt, you need to swap the single and double quotes. You need to wrap the entire

Use mongoexport with a --query for ISODate

我的未来我决定 提交于 2020-03-13 06:08:26
问题 I have this query but i´m getting a syntax error: unexpected identifier mongoexport --db ium --collection events \ --query 'db.events.find({'created_at' : { $gte: ISODate("2016-03-01T00:00:00.001Z"), $lte: ISODate("2016-03-29T23:59:59:59.000Z") }, "name" : "UPDATE_SUCCESS"})' \ --out guille1_test.json what can it be wrong? 回答1: You need to use "extended json" in queries with mongoexport. So the way to specify "dates" is with $date instead. And the --query is just the "query string" in JSON

MongoDB数据备份恢复

左心房为你撑大大i 提交于 2020-01-17 13:52:13
备份恢复工具介绍 (1)** mongoexport/mongoimport (2)***** mongodump/mongorestore 应用场景总结: mongoexport/mongoimport:json csv 1、异构平台迁移 mysql <---> mongodb 2、同平台,跨大版本:mongodb 2 ----> mongodb 3 mongodump/mongorestore 日常备份恢复时使用. mongoexport具体用法如下所示: $ mongoexport --help 参数说明: -h:指明数据库宿主机的IP -u:指明数据库的用户名 -p:指明数据库的密码 -d:指明数据库的名字 -c:指明collection的名字 -f:指明要导出那些列 -o:指明到要导出的文件名 -q:指明导出数据的过滤条件 --authenticationDatabase admin 1.单表备份至json格式 例:备份itemtest库下的sec表 mongoexport -uroot -proot123 --port=27017 --authenticationDatabase admin -d itemtest -c sec -o /mongodb/log.json 注:备份文件的名字可以自定义,默认导出了JSON格式的数据。 2. 单表备份至csv格式