fix query condition for tingodb

This commit is contained in:
Ivan Socolsky 2016-12-23 19:19:48 -03:00
parent f69d5a5bb4
commit bb489df824
No known key found for this signature in database
GPG Key ID: FAECE6A05FAA4F56
1 changed files with 17 additions and 9 deletions

View File

@ -931,18 +931,26 @@ Storage.prototype.updateHasBalance = function(addresses, hasBalance, cb) {
Storage.prototype.fetchAddressesWithBalance = function(walletId, cb) {
var self = this;
this.db.collection(collections.ADDRESSES).find({
walletId: walletId,
$or: [{
function getResult(cb) {
self.db.collection(collections.ADDRESSES).find({
walletId: walletId,
hasBalance: true,
}, {
hasBalance: {
$exists: false
},
}]
}).toArray(function(err, result) {
}).toArray(function(err, result) {
if (err) return cb(err);
if (!_.isEmpty(result)) return cb(null, result);
self.db.collection(collections.ADDRESSES).find({
walletId: walletId,
hasBalance: {
$exists: false
},
}).toArray(cb);
});
};
getResult(function(err, result) {
if (err) return cb(err);
if (!result) return cb();
var addresses = _.map(result, function(address) {
return Model.Address.fromObj(address);
});