其他命令对我来说可以正常工作,例如:
let commandDictionary = ["count": "trials"]
let error: NSError?
let result = myConnection.runCommandWithDictionary(
commandDictionary,
onDatabaseName: databaseName,
error: &error
)
但是,尝试distinct
命令不会:
let commandDictionary = ["distinct": "trials", "key": "location"]
let error: NSError?
let result = myConnection.runCommandWithDictionary(
commandDictionary,
onDatabaseName: databaseName,
error: &error
)
运行后,值为error
:Optional("MONGO_COMMAND_FAILED: The command returned with \'ok\' value of 0")
。在 shell 中运行什么(我相信)是相同的命令给了我理智的值:
db.runCommand({distinct: "trials", key: "location"})
更新#1:
另外,MongoConnection.serverVersion()
给我:"2.6.3"
,并MongoConnection.serverError()
返回nil
。在 shell 中运行命令时,详细的服务器日志会显示这一点:
2014-12-12T10:11:54.556-0500 [conn69] command eim.$cmd command: distinct { distinct: "trials", key: "metadata.location" } keyUpdates:0 numYields:0 locks(micros) r:606 reslen:210 0ms
他们为 ObjCMongoDb 运行的命令显示了这一点:
2014-12-12T10:10:25.945-0500 [conn171] command eim.$cmd command: isMaster { key: "metadata.location", distinct: "trials" } ntoreturn:1 keyUpdates:0 numYields:0 reslen:138 0ms
更新#2:
似乎distinct
命令在某处被映射到isMaster
命令。这发生在其他命令上。例如,命令{listDatabases:1}
也映射到isMaster
。但是,该命令{buildInfo:1}
已正确映射到buildInfo
.