mongodb检查使用副本集中的哪个节点

时间:2019-12-27 06:30:59

标签: mongodb

我正在使用pymongo 3.9.0连接到启用副本集的mongodb3.4.18,并且我想知道哪个节点用于查找查询。

我尝试过collection.find()。explain(),但似乎没有此信息;我也尝试过mongostat --discover,但失败了 Failed: not authorized on admin to execute command { serverStatus: 1, recordStats: 0, $queryOptions: { $readPreference: { mode: "secondaryPreferred" } }我仅在某些特定数据库上具有身份验证。

有没有办法做到这一点?谢谢。


在pymongo中,我做类似的事情

client = pymongo.MongoClient(ip, port, w=1)
client.admin.authenticate(user, password, db)
print client[db][col_name].find(query, fields).explain()

在bash中,我只需运行

mongostat --host=ip:port --discover --username=user --password=password --authenticationDatabase=db

0 个答案:

没有答案