use countDocuments

This commit is contained in:
Andris Reinman 2019-05-08 16:30:57 +03:00
parent 4e54ab5a6b
commit 268fbddc95

View file

@ -30,24 +30,26 @@ module.exports = server => (path, session, callback) => {
return callback(null, 'NONEXISTENT'); return callback(null, 'NONEXISTENT');
} }
db.database db.database.collection('messages').countDocuments(
.collection('messages') {
.find({
mailbox: mailboxData._id mailbox: mailboxData._id
}) },
.maxTimeMS(consts.DB_MAX_TIME_MESSAGES) {
.count((err, total) => { maxTimeMS: consts.DB_MAX_TIME_MESSAGES
},
(err, total) => {
if (err) { if (err) {
return callback(err); return callback(err);
} }
db.database db.database.collection('messages').countDocuments(
.collection('messages') {
.find({
mailbox: mailboxData._id, mailbox: mailboxData._id,
unseen: true unseen: true
}) },
.maxTimeMS(consts.DB_MAX_TIME_MESSAGES) {
.count((err, unseen) => { maxTimeMS: consts.DB_MAX_TIME_MESSAGES
},
(err, unseen) => {
if (err) { if (err) {
return callback(err); return callback(err);
} }
@ -58,8 +60,10 @@ module.exports = server => (path, session, callback) => {
uidValidity: mailboxData.uidValidity, uidValidity: mailboxData.uidValidity,
unseen unseen
}); });
}); }
}); );
}
);
} }
); );
}; };