|
| 1 | +================================ |
| 2 | +Roll Back to a Version 1.8 Index |
| 3 | +================================ |
| 4 | + |
| 5 | +.. default-domain:: mongodb |
| 6 | + |
| 7 | + |
| 8 | +MongoDB version 2.0 and later supports the old index format. But old versions |
| 9 | +will not support the new format. If you need to roll back to an older |
| 10 | +version, the server will run, but queries and other operations involving |
| 11 | +the newer indexes will log and return an error. Thus, you will need to |
| 12 | +re-create any new index you would like to use on an old server. |
| 13 | + |
| 14 | +Versions prior to 1.8.2, inclusive, are not aware of the index version |
| 15 | +field. If you rollback a ``{v:1}`` index to 1.8.2 and re-index it, its |
| 16 | +version will still be marked ``{v: 1}``, although it actual is now version ``{v:0}``. |
| 17 | +If you upgrade again to 2.0, this index will not work, even though it is |
| 18 | +marked as ``{v: 1}`` in ``system.indexes``. If you must roll back to a |
| 19 | +version prior to 1.8.2, you must delete the index then create it again |
| 20 | +(instead of simply re-indexing). |
| 21 | + |
| 22 | +Building a {v:0} Index |
| 23 | +---------------------- |
| 24 | + |
| 25 | +You can still create a ``{v:0}`` index with MongoDB version 2.0 or later. To do so, add the |
| 26 | +option ``{v:0}`` in the index creation command. For example in the :program:`mongo` |
| 27 | +shell: |
| 28 | + |
| 29 | +.. code-block:: javascript |
| 30 | + |
| 31 | + // defaults to a v:1 index |
| 32 | + db.foo.ensureIndex({name:1}) |
| 33 | + db.system.indexes.find() |
| 34 | + { "v" : 1, "key" : { "_id" : 1 }, "ns" : "mydb.foo", "name" : "_id_" } |
| 35 | + { "v" : 1, "key" : { "name" : 1 }, "ns" : "mydb.foo", "name" : "name_1" } |
| 36 | + db.foo.dropIndex({name:1}) |
| 37 | + { "nIndexesWas" : 2, "ok" : 1 } |
| 38 | + |
| 39 | + // create a v:0 index |
| 40 | + db.foo.ensureIndex({name:1},{v:0}) |
| 41 | + db.system.indexes.find() |
| 42 | + { "v" : 1, "key" : { "_id" : 1 }, "ns" : "mydb.foo", "name" : "_id_" } |
| 43 | + |
| 44 | + { "v" : 0, "key" : { "name" : 1 }, "ns" : "mydb.foo", "name" : "name_1" } |
| 45 | + |
| 46 | +.. seealso:: :ref:`2.0-new-index-format` and :ref:`2.0-convert-to-new-index-format` |
0 commit comments