MongoEngine如何处理索引(创建,更新,删除)? [英] How does MongoEngine handle Indexes (creation, update, removal)?

查看:2321
本文介绍了MongoEngine如何处理索引(创建,更新,删除)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于设置Mongo索引的最佳实践问题。 Mongoengine是Python ORM包装器,允许您在Document元类中设置索引。

Best practice question about setting Mongo indexes. Mongoengine, the Python ORM wrapper, allows you to set indexes in the Document meta class.

这个元类何时被内省并添加了索引?我可以通过mongoengine Document类构建一个集合,然后在事后添加一个索引吗?

When is this meta class introspected and the index added? Can I build a collection via a mongoengine Document class and then add an index after the fact?

如果我从元类中删除索引,是否会自动从索引中删除索引相应的集合?

If I remove the index from the meta class, is the index automatically removed from the corresponding collection?

谢谢,

推荐答案

你可以添加一个任何时候索引, ensureIndex 将在幕后调用,如果不存在则会被添加。

You can add an index at any time and ensureIndex will be called behind the scenes so it will be added if it doesn't exist.

如果从元中删除索引 - 您将不得不使用pymongo或shell来删除索引。

If you remove an index from the meta - you will have to use pymongo or the shell to remove the index.

这篇关于MongoEngine如何处理索引(创建,更新,删除)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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