Skip to content

Instantly share code, notes, and snippets.

@akm
Created April 15, 2014 12:43
Show Gist options
  • Select an option

  • Save akm/10729459 to your computer and use it in GitHub Desktop.

Select an option

Save akm/10729459 to your computer and use it in GitHub Desktop.
MongoDB-2.6.0で変わったensureIndexの振る舞い ref: http://qiita.com/akm/items/799f2c7a6a6697f25127
% mongo test
MongoDB shell version: 2.4.6
connecting to: test
>
> db.t1.drop();
false
> db.createCollection("t1", {});
{ "ok" : 1 }
> db.t1.ensureIndex({f1: 1}, {uniq: true});
> db.t1.ensureIndex({f1: 1}, {});
>
> db.t1.dropIndex({f1: 1})
{ "nIndexesWas" : 2, "ok" : 1 }
> db.t1.ensureIndex({f1: 1}, {});
>
% mongo test
MongoDB shell version: 2.4.6
connecting to: test
>
> db.t1.drop();
true
> db.createCollection("t1", {});
{ "ok" : 1 }
> db.t1.ensureIndex({f1: 1}, {uniq: true});
> db.t1.ensureIndex({f1: 1}, {});
{
"connectionId" : 1,
"err" : "Index with name: f1_1 already exists with different options",
"code" : 17427,
"n" : 0,
"ok" : 1
}
>
> db.t1.dropIndex({f1: 1})
{ "nIndexesWas" : 2, "ok" : 1 }
> db.t1.ensureIndex({f1: 1}, {});
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment