Using hint() in a sharded environment

19 views
Skip to first unread message

Kev

unread,
Dec 31, 2011, 4:12:33 PM12/31/11
to mongodb-user
I have a table, mytable with indexes hash_1__id_1 and hash_1_uid_1.
The shard key of the table is hash_1__id_1.

By executing the following query:
db.mytable.find({'hash' : 1234, 'uid', 1111})
using explain i see that it is actually using the hash_1__id_1 index
instead of the hash_1_uid_1.

Is this because of the fact that hash_1__id_1 is the sharded key? I
tried to force it to use the other index to see if it is faster as
follows:

db.mytable.find({'hash' : 1234, 'uid', 1111}).hint("hash_1_uid_1")

but that results in an error:

Sat Dec 31 16:03:42 uncaught exception: error: {
"$err" : "could not initialize cursor across all shards because : bad
hint @ database5/shard5:27018,shard5r:27018",
"code" : 14827
}

Is this a problem with my shard key? Or is there a way around this.

Much appreciated and happy new year!

Eliot Horowitz

unread,
Dec 31, 2011, 4:28:53 PM12/31/11
to mongod...@googlegroups.com
Are you sure that there is an index on ( hash , uid )?
Would be surprised if it used ( hash , id ) rather than ( hash , uid )
for that query.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>

Kev

unread,
Dec 31, 2011, 4:35:34 PM12/31/11
to mongodb-user
I figured this out just now actually. Somehow, the index was not
created on the 5th shard, but on every other shard. Recreating the
index solved this issue. Thanks for the quick reply ;0
Reply all
Reply to author
Forward
0 new messages