发布于 2015-09-14 14:57:07 | 84 次阅读 | 评论: 0 | 来源: 网络整理

重要

Use this procedure only if you must have indexes that are compatible with a version of MongoDB earlier than 2.0.

MongoDB version 2.0 introduced the {v:1} index format. MongoDB versions 2.0 and later support both the {v:1} format and the earlier {v:0} format.

MongoDB versions prior to 2.0, however, support only the {v:0} format. If you need to roll back MongoDB to a version prior to 2.0, you must drop and re-create your indexes.

To build pre-2.0 indexes, use the dropIndexes() and ensureIndex() methods. You cannot simply reindex the collection. When you reindex on versions that only support {v:0} indexes, the v fields in the index definition still hold values of 1, even though the indexes would now use the {v:0} format. If you were to upgrade again to version 2.0 or later, these indexes would not work.

Example

Suppose you rolled back from MongoDB 2.0 to MongoDB 1.8, and suppose you had the following index on the items collection:

{ "v" : 1, "key" : { "name" : 1 }, "ns" : "mydb.items", "name" : "name_1" }

The v field tells you the index is a {v:1} index, which is incompatible with version 1.8.

To drop the index, issue the following command:

db.items.dropIndex( { name : 1 } )

To recreate the index as a {v:0} index, issue the following command:

db.foo.ensureIndex( { name : 1 } , { v : 0 } )
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务