pymongo中的collection.getIndexes()shell命令等效于什么? [英] What is the equivalent of the collection.getIndexes() shell command in pymongo?

查看:93
本文介绍了pymongo中的collection.getIndexes()shell命令等效于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎找不到作为pymongo的Collection对象的一部分实现的getIndexes()命令-这是故意的吗?它是在类层次结构中的其他地方实现的吗?

I can't seem to find a getIndexes() command implemented as part of pymongo's Collection object - is that intentional? is it implemented somewhere else in the class hierarchy?

如果不是,那么获得相同效果的pymongo规范方法是什么?

if it isn't, what's the pymongo canonical way for getting the same effect?

推荐答案

您可能正在寻找的是

What you might be looking for is index_information() at the Collection level. From the docs:

获取有关此收藏集索引的信息.

Get information on this collection’s indexes.

返回一个字典,其中的键是索引名(由create_index()返回),值是包含每个索引信息的字典.

Returns a dictionary where the keys are index names (as returned by create_index()) and the values are dictionaries containing information about each index.

>>> db.test.index_information()
{u'_id_': {u'key': [(u'_id', 1)]},
u'x_1': {u'unique': True, u'key': [(u'x', 1)]}}

这篇关于pymongo中的collection.getIndexes()shell命令等效于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆