本文介绍了oplog.rs中ts字段上的索引未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序通过查询ts字段来读取mongodb 2.2副本集中的oplog.rs集合.

I have an application that reads the oplog.rs collection in a mongodb 2.2 replica set by querying on the ts field.

我在ts字段上添加了一个索引,但是当在操作日志中插入新条目时,该索引不会更新.

I added an index on the ts field, but it doesn't get updated when new entries are inserted into the oplog.

我想念什么?我在mongodb文档中找不到关于上限集合索引的任何支持(相反),并且找不到关于oplog的任何特殊信息.

What am I missing? I can't find anything in the mongodb docs about indexes on capped collections are not supported (rather the opposite), and I can't find any info about the oplog being special.

谢谢

推荐答案

您已经发现,系统集合(例如local.oplog.rs*.system.profile)不支持二级索引.在MongoDB 2.4和更早的版本中,索引似乎已创建,但从未真正更新过.如果尝试使用不受支持的更改(例如尝试创建其他索引)直接更新系统集合,则新版本的MongoDB(2.6+)会返回错误.

As you've discovered, secondary indexes are not supported on system collections such as local.oplog.rs and *.system.profile. In MongoDB 2.4 and older the indexes would appear to have been created, but were never actually updated. Newer versions of MongoDB (2.6+) return an error if you try to directly update a system collection with an unsupported change such as attempting to create additional indexes.

oplog.rs集合绝对是特殊的",因为其预期用途仅用于复制.复制内部人员在此基础上对oplog的预期操作进行了一些假设.例如,复制仅需要插入操作日志条目-与您可能自己创建的带上限的集合不同,操作日志条目从不进行更新.

The oplog.rs collection is definitely "special" because its intended use is only for replication. The replication internals make some assumptions about expected operations for the oplog on this basis. For example, replication only needs to insert oplog entries -- unlike a capped collection that you may create yourself, oplog entries are never updated.

应用程序应使用可定位游标来读取操作日志.如果他们需要关注插入操作日志中的新条目,或者使用 $natural订单.

Applications are expected to read the oplog with a tailable cursor if they need to follow new entries that are inserted into the oplog, or to do a find using $natural order.

零售光标教程详细介绍了用法,但要注意的几点是:

The tailable cursor tutorial goes into some more detail on usage, but a few particular points to note are:

这篇关于oplog.rs中ts字段上的索引未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 01:21