时间:2021-07-01 10:21:17 帮助过:3人阅读
在currentOp()可以看到,相当于ISODate("2013-02-24T16:00:00Z")
"ns" : "log.log",
"query" : {
"count" : "log",
"query" : {
"optime" : {
"$gte" : ISODate("2013-02-24T16:00:00Z")
}
},
"fields" : {
}
}
2.ISODate方式,查询大于等于北京时间2013年2月25日0点的数据记录数方法为,MongoDB中的格式是标准时间,相差8小时:
db.log.find({"optime":{$gte:ISODate("2013-02-24T16:00:00Z")}}).count()
mongodump 按日期导出数据
mongodump --query选项可指定查询条件,按日期范围导出数据,并不支持ISODate格式:
mongodump -umonitor -p‘xxxxxx‘ --port 20011 -d exaitem_gmsbatchtask -c jdgmsbatchtask -q ‘{"addDate":{$gte:ISODate("2013-02-10T16:00:00.000Z")}}‘ -o jdgmsbatchtask
connected to: 127.0.0.1:20011
Tue Feb 26 10:12:03 Assertion: 10340:Failure parsing JSON string near: "addDate":
0x5811c2 0x5287d4 0x528b4e 0xaa4c3b 0xa9b18d 0xa9f122 0x305061d994 0x4fe4c9
mongodump(_ZN5mongo11msgassertedEiPKc+0x112) [0x5811c2]
mongodump(_ZN5mongo8fromjsonEPKcPi+0x444) [0x5287d4]
mongodump(_ZN5mongo8fromjsonERKSs+0xe) [0x528b4e]
mongodump(_ZN4Dump3runEv+0x33b) [0xaa4c3b]
mongodump(_ZN5mongo4Tool4mainEiPPc+0x169d) [0xa9b18d]
mongodump(main+0x32) [0xa9f122]
/lib64/libc.so.6(__libc_start_main+0xf4) [0x305061d994]
mongodump(__gxx_personality_v0+0x3d1) [0x4fe4c9]
assertion: 10340 Failure parsing JSON string near: "addDate":
仅支持时间戳,并转换成毫秒,如下正常导出数据:
date -d 2013-02-25 +%s
1361721600
mongodump -umonitor -p‘xxxxxx‘ --port 20011 -d exaitem_gmsbatchtask -c jdgmsbatchtask -q ‘{"addDate":{$gte:Date(1361721600000)}}‘ -o jdgmsbatchtask
connected to: 127.0.0.1:20011
DATABASE: exaitem_gmsbatchtask to jdgmsbatchtask/exaitem_gmsbatchtask
exaitem_gmsbatchtask.jdgmsbatchtask to jdgmsbatchtask/exaitem_gmsbatchtask/jdgmsbatchtask.bson
847400/81641905 1%
两个日期之间查询如下:
mongodump -umonitor -p‘xxxxxx‘ --port 20011 -d exaitem_gmsbatchtask -c jdgmsbatchtask -q ‘{"addDate":{$gte:Date(1360598400000),$lt:Date(1361851200000)}}‘ -o jdgmsbatchtask
另外如果使用双引号,可通过转义符。
mongodump --query "{\"ts\":{\"\$gt\":{\"\$date\":`date -d 2011-08-10 +%s`000},\"\$lte\":{\"\$date\":`date -d 2011-08-11 +%s`000}}}"
最后,为了导出一个月的数据,发现_id字段默认的,采用ObjectId来完成的。
PRIMARY> db.jdgmslog.find({"optime":{$gte:ISODate("2013-01-26T00:00:00Z")}}).limit(1)
{ "_id" : ObjectId("51031c80c8665789e6a9b7fe"), "source" : 2, "optime" : ISODate("2013-01-26T00:00:00.003Z")}
mongodump -umonitor -p‘xxxxxx‘ --port 20011 -d exaitem_gmslog -c jdgmslog -q ‘{"_id" : {$gte:ObjectId("51031c80c8665789e6a9b7fe")}}‘ -o jdgmslog_month
connected to: 127.0.0.1:20011
DATABASE: exaitem_gmslog to jdgmslog_month/exaitem_gmslog
exaitem_gmslog.jdgmslog to jdgmslog_month/exaitem_gmslog/jdgmslog.bson
639500/213149563 0%
1238200/213149563 0%
2 回复mongodump的进度条在条件查询时,显示任然是全量的,不影响数据按条件导出。
Thu Apr 3 17:51:14.356 Collection File Writing Progress: 862600/43909859 1% (objects)
Thu Apr 3 18:05:11.307 Collection File Writing Progress: 870000/43909859 1% (objects)
Thu Apr 3 18:05:11.309 871057 objects
Thu Apr 3 18:05:11.310 Metadata for db.t to dump/db/t.metadata.json
mongoexport用法类似。
MongoDb
标签: