Skip to content

Commit 483b6ac

Browse files
committed
Add forceand option
1 parent 007b830 commit 483b6ac

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

HISTORY.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
History
22
=======
33

4+
####2020-08-04 v0.1.20
5+
Allow the result to be returned in the $and form even if there is only one condition by passing {forceand: true} in the options @dhendo
6+
47
####2020-08-04 v0.1.19
58
Dependabot upgrade of qs @dhendo
69

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ module.exports = {
156156
// Now build the final object
157157
switch(conditions.length) {
158158
case 1:
159-
filterQuery = conditions[0];
159+
if(options.forceand){
160+
filterQuery.$and = conditions;
161+
}else{
162+
filterQuery = conditions[0];
163+
}
160164
break;
161165
case 0:
162166
break;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongo-queryfilter",
3-
"version": "0.1.19",
3+
"version": "0.1.20",
44
"description": "Safely create a simple mongo query from a querystring collection to allow filtering",
55
"main": "index.js",
66
"scripts": {

test/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,18 @@ suite('Date filtering', function () {
709709
(out.value.$lte*1).should.be.approximately(new Date()*1, 1000);
710710
done();
711711
});
712+
713+
714+
test('should allow the result to always be returned as a $and', function (done) {
715+
// define a function that returns an operator $thing, that doubles the value
716+
// Set for the lifetime of qf
717+
var out = qf.filter('price=3', {forceand: true});
718+
should.exist(out);
719+
out.should.have.property('$and');
720+
out.$and.should.have.length(1);
721+
out.$and[0].should.have.property("price", "3");
722+
done();
723+
});
712724
});
713725

714726
suite('The filter values', function () {

0 commit comments

Comments
 (0)