我想转储数据库的某些部分,尤其是使用 -q / --query 选项的集合的某些部分。这是我正在做的事情:
mongodump --host ... -o ... -q "{ pipe: DBRef(\"pipe\", ObjectId($2)) }"
转储正在运行,但速度非常慢。有 3M 个对象,并且pipe
属性上有一个索引,所以事情不应该那么慢。看起来查询正在扫描整个集合。
有任何想法吗 ?
谢谢
您可以打开探查器并查看发生了什么。基本上,当您指定一个查询时,您转储只会运行此查询并将答案转换为转储。首先,我认为它会对查询进行快照,但不会。
使用探查器,我得到以下结果:
为此: mongodump -h localhost:27417 -u ... -p ... -d test1 -ct
connected to: localhost:27417
Fri Aug 30 11:47:56.288 DATABASE: test1 to dump/test1
Fri Aug 30 11:47:56.289 test1.t to dump/test1/t.bson
Fri Aug 30 11:47:56.291 101 objects
Fri Aug 30 11:47:56.291 Metadata for test1.t to dump/test1/t.metadata.json
我在探查器中有这个:
{
"op" : "query",
"ns" : "test1.t",
"query" : {
"query" : {
},
"$snapshot" : true
},
"ntoreturn" : 0,
"ntoskip" : 0,
"nscanned" : 101,
"keyUpdates" : 0,
"numYield" : 0,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(499),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(2),
"w" : NumberLong(4)
}
},
"nreturned" : 101,
"responseLength" : 11410,
"millis" : 0,
"ts" : ISODate("2013-08-30T09:54:18.605Z"),
"client" : "127.0.0.1",
"allUsers" : [
{
"user" : "__system",
"userSource" : "local"
}
],
"user" : "__system@local"
}
为此: mongodump -h localhost:27417 -u ... -p ... -d test1 -ct -q {\'bb\':8},我有这个:
connected to: localhost:27417
Fri Aug 30 11:58:15.332 DATABASE: test1 to dump/test1
Fri Aug 30 11:58:15.334 test1.t to dump/test1/t.bson
Fri Aug 30 11:58:15.335 1 objects
Fri Aug 30 11:58:15.336 Metadata for test1.t to dump/test1/t.metadata.json
在分析器中:
{
"op" : "query",
"ns" : "test1.t",
"query" : {
"b.b" : 8
},
"ntoreturn" : 0,
"ntoskip" : 0,
"nscanned" : 1,
"keyUpdates" : 0,
"numYield" : 0,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(174),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(3),
"w" : NumberLong(4)
}
},
"nreturned" : 1,
"responseLength" : 134,
"millis" : 0,
"ts" : ISODate("2013-08-30T09:58:15.335Z"),
"client" : "127.0.0.1",
"allUsers" : [
{
"user" : "__system",
"userSource" : "local"
}
],
"user" : "__system@local"
}
这意味着它利用了我指定的索引,因此其他一些事情可能是瓶颈或您指定的索引不支持查询。