Closed alexborisov closed 8 years ago
Hi @alexborisov and thanks for using this library and submitting such a detailed ticket 😄
I have found, and fixed, two unrelated errors which would have prevented this kind of custom query from working correctly. I have also added a test for this make sure this works as intended in all future versions. With the new version 4.0.1
this custom function should work for you:
var qs = new MongoQS({
custom: {
assigned: function(query, input) {
// make sure we handle normal string queries (?assigned=1111)
if (typeof input === 'string') {
input = input.split(',');
}
query['assigned.users._id'] = {
// since query strings are strings we need to parse them to integers
$in: inputValue.map(id => parseInt(id, 10))
};
}
}
});
thank you! 👍
I want to create a custom query for an array. This is my structure:
I expect that for this query
?assigned[]=1111&assigned[]=2222
I would write a function