loopback-connector-mongodb
Advanced tools
Comparing version 1.2.5 to 1.2.6
@@ -473,2 +473,3 @@ /*! | ||
var order = {}; | ||
if (filter.order) { | ||
@@ -479,3 +480,2 @@ var keys = filter.order; | ||
} | ||
var args = {}; | ||
for (var index in keys) { | ||
@@ -485,10 +485,17 @@ var m = keys[index].match(/\s+(A|DE)SC$/); | ||
key = key.replace(/\s+(A|DE)SC$/, '').trim(); | ||
if(key === idName) { | ||
key = '_id'; | ||
} | ||
if (m && m[1] === 'DE') { | ||
args[key] = -1; | ||
order[key] = -1; | ||
} else { | ||
args[key] = 1; | ||
order[key] = 1; | ||
} | ||
} | ||
cursor.sort(args); | ||
} else { | ||
// order by _id by default | ||
order = {_id: 1}; | ||
} | ||
cursor.sort(order); | ||
if (filter.limit) { | ||
@@ -495,0 +502,0 @@ cursor.limit(filter.limit); |
{ | ||
"name": "loopback-connector-mongodb", | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"description": "LoopBack MongoDB Connector", | ||
@@ -18,3 +18,3 @@ "keywords": [ | ||
"mongodb": "~1.4.3", | ||
"async": "~0.8.0", | ||
"async": "~0.9.0", | ||
"debug": "~0.8.1" | ||
@@ -29,3 +29,3 @@ }, | ||
"mocha": "~1.18.2", | ||
"rc": "~0.3.5" | ||
"rc": "~0.4.0" | ||
}, | ||
@@ -32,0 +32,0 @@ "repository": { |
@@ -57,3 +57,5 @@ // This test written in mocha+should.js | ||
PostWithNumberId.destroyAll(function () { | ||
done(); | ||
PostWithStringId.destroyAll(function () { | ||
done(); | ||
}); | ||
}); | ||
@@ -462,2 +464,28 @@ }); | ||
it('find should order by id if the order is not set for the query filter', | ||
function (done) { | ||
PostWithStringId.create({id: '2', title: 'c', content: 'CCC'}, function (err, post) { | ||
PostWithStringId.create({id: '1', title: 'd', content: 'DDD'}, function (err, post) { | ||
PostWithStringId.find(function (err, posts) { | ||
should.not.exist(err); | ||
posts.length.should.be.equal(2); | ||
posts[0].id.should.be.equal('1'); | ||
PostWithStringId.find({limit: 1, offset: 0}, function (err, posts) { | ||
should.not.exist(err); | ||
posts.length.should.be.equal(1); | ||
posts[0].id.should.be.equal('1'); | ||
PostWithStringId.find({limit: 1, offset: 1}, function (err, posts) { | ||
should.not.exist(err); | ||
posts.length.should.be.equal(1); | ||
posts[0].id.should.be.equal('2'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('should report error on duplicate keys', function (done) { | ||
@@ -464,0 +492,0 @@ Post.create({title: 'd', content: 'DDD'}, function (err, post) { |
72673
1490
- Removedasync@0.8.0(transitive)
Updatedasync@~0.9.0