84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
写了个采集爬虫,采集了大概180万条URL,现在要给它平均分割成多份,然后保存文件。请问要怎么做比较好。
学习是最好的投资!
使用mongo自带的工具可以导出为json或者cvs或者txt格式.
json
cvs
txt
格式为
mongoexport --db {dbname} --collection {collectionname} --out traffic.json
数据库为test,collections为col。里面的数据如下
test
collections
col
> db.col.find().pretty() { "_id" : ObjectId("573173ce83358fa60470e0db"), "id" : 1, "name" : "adamweixuan" } { "_id" : ObjectId("573173e983358fa60470e0dc"), "id" : 2, "name" : "nicholas" } { "_id" : ObjectId("573173f383358fa60470e0dd"), "id" : 3, "name" : "test" } { "_id" : ObjectId("5731740383358fa60470e0de"), "id" : 4, "name" : "test001" } { "_id" : ObjectId("5731740a83358fa60470e0df"), "id" : 5, "name" : "test002" } { "_id" : ObjectId("5731741283358fa60470e0e0"), "id" : 6, "name" : "test003" }
现在平均分成三个文件导出。
# id 不大于2的 mongoexport --port 10510 -d test -c col -q '{id : {$lte:2}}' --out ./names1.txt # id 在2和4之间的 mongoexport --port 10510 -d test -c col -q '{id : {$gt:2} , id :{$lte:4}}' --out ./names2.txt # id大于4的 mongoexport --port 10510 -d test -c col -q '{id : {$gt:4}}' --out ./names3.txt
你可以写个脚本,试试。
说明:-d 是指定database ,-c 指定 集合 ,-q 是查询,后面的文件格式支持json、cvs、txt
json、cvs、txt
180w的数据通常来说……不用分割。Shard key的选取原则其实在官方文档中已经有详细说明,想了解的话不妨参考一下。
使用mongo自带的工具
使用mongo自带的工具可以导出为
json
或者cvs
或者txt
格式.格式为
举个栗子
数据库为
test
,collections
为col
。里面的数据如下现在平均分成三个文件导出。
你可以写个脚本,试试。
说明:-d 是指定database ,-c 指定 集合 ,-q 是查询,后面的文件格式支持
json、cvs、txt
180w的数据通常来说……不用分割。
Shard key的选取原则其实在官方文档中已经有详细说明,想了解的话不妨参考一下。