Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the MongoDB CPAN distribution.

Maintainer(s)' notes

Please don't report bugs here. Please use the MongoDB Perl driver issue tracker instead.

Report information
The Basics
Id: 77754
Status: resolved
Priority: 0/
Queue: MongoDB

People
Owner: Nobody in particular
Requestors: kalman.bodor [...] propertyshark.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.45
Fixed in: (no value)



Subject: Order of columns in hint() not preserved, name of index invalid
Trying to use a hint: $connection->collection()->find()->hint({ index_column_1 => 1, index_column_2 => 1, index_column_3 => 1 }) Results in a query: { query : {}, $hint : { index_column_2 : 1, index_column_3 : 1, index_column_1 : 1 } } which results in "query error: bad hint" in the case of an index created like this: db.collection.ensureIndex({ index_column_1 : 1, index_column_2 : 1, index_column_3 : 1 }). It turns out that despite the hint() function in the mongo shell accepting a "hash", mongodb does care about the order in which the columns are specified. So db.collection.find().hint({ a : 1, b : 1 }) is not the same as db.collection.find().hint({ b : 1, a : 1 }) (the latter causing a query error: bad hint). By supporting this behavior, the perl driver should keep the order of the columns specified within the hint. This might not be possible with perl, as the order of the keys in a hash is "random". Maybe an array, instead of a hash, would be preferable (eg. find()->hint([ index_column_1, index_column_2, index_column_3 ]) ). Also, specifying the name of the index ("index_column_1_1_index_column_2_1_index_column_3_1") instead of a hash gives the same "bad hint" error. Specifying the name of the index in the hint works in the mongo shell, though. Also, the documentation is a bit ambiguous, as under the "hint" chapter in the MongoDB::Cursor page says "Force Mongo to use a specific index for a query." and the example code says "my $cursor = $coll->query->hint({'x' => 1});", not specifying what 'x' can be: columns from an index or the name of the index? (both are accepted ways of forcing an index by the mongodb). Error reproduced on mongodb versions 2.0.2 and 2.0.4. Perl version: 5.12.4. Linux distro: 3.1.0-gentoo.
Not a bug, since the driver supports using Tie::IxHash where ordering is required.