Mongodump使用DBRef标准和索引?

时间:2013-08-29 15:25:51

标签: mongodb dbref mongodump

我想使用-q / --query选项转储数据库的某些部分,尤其是集合的某些部分。这就是我正在做的事情:

mongodump --host ... -o ... -q "{ pipe: DBRef(\"pipe\", ObjectId($2)) }"

转储正在运行,但速度很慢。有3M对象,pipe属性上有一个索引,所以事情不应该那么慢。看起来查询正在扫描整个集合。

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:0)

您可以打开探查器,看看发生了什么。基本上,当您指定查询时,转储将仅运行此查询并将答案转换为转储。首先,我会对查询进行快照但不是。

使用profiler我有以下结果:

为此:mongodump -h localhost:27417 -u ... -p ... -d test1 -c t

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 -c t -q {\'b.b \':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"
}

这意味着它利用了我指定的索引,因此您指定的索引可能不支持瓶颈或查询。