Description
Node version: v8.17.0
Sails version (sails): 1.2.3
ORM hook version (sails-hook-orm): 2.1.1
DB adapter & version: [email protected]
No additional top-level dependencies present. Confirmed with merely sails
, sails-hook-orm
and sails-mongo
.
There appears to be an issue where the sails-mongo
Waterline adapter fails to transform input query filter values to Mongo ObjectId
instances where appropriate, instead leaving such values as simple strings.
This occurs in cases where the target field appears to be an appropriate candidate (a primary key) for normalisation to ObjectId
and only affects the following operators:
<
<=
>
>=
For instance, the following Waterline query:
Post.find({
id: {
'>': '5e9a49923a48025cccdaee43',
},
});
Will ultimately issue this to MongoDB:
{
_id: {
'$gt': '5e9a49923a48025cccdaee43'
}
}
Rather than the expected query of:
{
_id: {
'$gt': ObjectId('5e9a49923a48025cccdaee43')
}
}
This results in an inability to perform a number of useful queries against PK fields (such as paging on document IDs) and feels inconsistent with the behaviour of the other Waterline query operators supported by sails-mongo
, as well as other adapters.
I've built a mostly minimal test case at Rua-Yuki/waterline-mongo-objectid-comparison-funk, which also contains more information about this issue.
A quick fix exists in the fpm-git/sails-mongo fork.