|
Closing as a duplicate of SERVER-11064 - the values in the index key pattern must now be a number > 0, a number < 0, or a string.
> db.foo.ensureIndex({a:true})
|
{
|
"ok" : 0,
|
"errmsg" : "bad index key pattern { a: true }: Values in index key pattern cannot be of type Bool. Only numbers > 0, numbers < 0, and strings are allowed.",
|
"code" : 67
|
}
|
> db.foo.ensureIndex({a:1.0})
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"ok" : 1
|
}
|
> db.foo.ensureIndex({a:1.5})
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 2,
|
"numIndexesAfter" : 3,
|
"ok" : 1
|
}
|
> db.foo.ensureIndex({a:NumberInt(2)})
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 3,
|
"numIndexesAfter" : 4,
|
"ok" : 1
|
}
|
> db.foo.ensureIndex({a:NumberLong(3)})
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 4,
|
"numIndexesAfter" : 5,
|
"ok" : 1
|
}
|
> db.foo.ensureIndex({a:"foo"})
|
{
|
"ok" : 0,
|
"errmsg" : "bad index key pattern { a: \"foo\" }: Unknown index plugin 'foo'",
|
"code" : 67
|
}
|
> db.foo.ensureIndex({a:[1,2,3]})
|
{
|
"ok" : 0,
|
"errmsg" : "bad index key pattern { a: [ 1.0, 2.0, 3.0 ] }: Values in index key pattern cannot be of type Array. Only numbers > 0, numbers < 0, and strings are allowed.",
|
"code" : 67
|
}
|
> db.foo.ensureIndex({a:{"foo":"bar"}})
|
{
|
"ok" : 0,
|
"errmsg" : "bad index key pattern { a: { foo: \"bar\" } }: Values in index key pattern cannot be of type Object. Only numbers > 0, numbers < 0, and strings are allowed.",
|
"code" : 67
|
}
|
> db.foo.getIndexes()
|
[
|
{
|
"v" : 1,
|
"key" : {
|
"_id" : 1
|
},
|
"name" : "_id_",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : 1
|
},
|
"name" : "a_1",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : 1.5
|
},
|
"name" : "a_1.5",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : 2
|
},
|
"name" : "a_2",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : NumberLong(3)
|
},
|
"name" : "a_3",
|
"ns" : "test.foo"
|
}
|
]
|
|
|
hari.khalsa@10gen.com: I'm not sure if you were going to use this ticket to touch up the index name creation in the server. If so, I'd suggest looking at this test for the PHP driver. My logic was:
- Float and integers are the only values that could be < 0 and thus create descending indexes, so "_-1" is appended.
- Everything else (boolean, float/int >= 0, and even null) would be 0 or a positive integer and thus create ascending indexes, so "_1" is appended
- Any string values (plugin names) are appended as-is (e.g. "_2d", "_invalidPlugin") for name generation. If the plugin is invalid, the server will throw an error in course.
|
> db.foo.ensureIndex({a:true})
|
> db.foo.ensureIndex({a:1.0})
|
> db.foo.ensureIndex({a:1.5})
|
> db.foo.ensureIndex({a:NumberInt(2)})
|
> db.foo.ensureIndex({a:NumberLong(3)})
|
> db.foo.ensureIndex({a:"foo"})
|
> db.foo.ensureIndex({a:[1,2,3]})
|
> db.foo.ensureIndex({a:{"foo":"bar"}})
|
> db.foo.getIndexes()
|
[
|
{
|
"v" : 1,
|
"key" : {
|
"_id" : 1
|
},
|
"name" : "_id_",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : true
|
},
|
"name" : "a_true",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : 1
|
},
|
"name" : "a_1",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : 1.5
|
},
|
"name" : "a_1.5",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : 2
|
},
|
"name" : "a_2",
|
"ns" : "test.foo"
|
},
|
{
|
"v" : 1,
|
"key" : {
|
"a" : NumberLong(3)
|
},
|
"name" : "a_3",
|
"ns" : "test.foo"
|
}
|
]
|
|