在mongoDB集合上设置ttl-是在应用程序中还是在shell中? [英] Setting ttl on a mongoDB collection - in application or shell?

查看:126
本文介绍了在mongoDB集合上设置ttl-是在应用程序中还是在shell中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为集合一次设置ttl,在构建使用mongoDB的Java应用程序时实现此目的的惯用方式是什么? ppl是否只是在shell中应用了这些设置?还是在应用程序代码中检查数据库中是否已经存在一个集合是正常的,如果不是,则使用所需的选项来创建它?

I would like to set the ttl for a collection once, what is the idiomatic way of achieving this when building a java application that uses mongoDB? Do ppl simply apply settings like these in the shell? Or in the application code is it normal to check if a collection is already in the DB, if it is not then create it with the desired options?

谢谢!

推荐答案

我再也不会在应用程序代码中进行索引构建了.

I never do index building in my application code anymore.

我承认我曾经这样做.每次我的应用程序启动时,我都会确保所有索引,直到突然之间,有一天,一个新手开发人员掌握了我的代码,并意外地删除了我的一个索引序列中的一个字符.

I confess that I used to. Everytime my application started up I would ensure all my indexes, until suddenly one day a beginner developer got hold of my code and accidently deleted a character within one of my index sequences.

因此,整个群集由于在前台处理此索引构建而冻结并崩溃.幸运的是,我有许多延迟的和无索引的建筑奴隶需要维修,但仍然损失了大约12个小时,因此又损失了12个小时的营业时间.

Consequently the entire cluster froze and went down due to processing, in the foreground, this index building. Fortunately I had a number of delayed and non-index building slaves to repair from but still, I lost about 12 hours all in all and in turn 12 hours of business.

我建议您不要在应用程序代码中建立索引,而要在您的mongo控制台中巧妙地建立索引.像这样的任何操作(甚至是TTL索引)都适用.

I would recommend you don't do your index building in the application code but instead carfully within your mongo console. That goes for any operation like this, even TTL indexing.

这篇关于在mongoDB集合上设置ttl-是在应用程序中还是在shell中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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