I am trying to count docs in mongodb request.
I can count count = docs.length
in toArray()
-s callback but allways gives 10
. A can do 2 same requests just replace find
to count
but it seems wrong
let count;
db.get().collection('images').find({
$and: [
{tags: { $in: tags }},
{date: {$gte: date.toISOString()}},
{title:{$regex: query, $options: "$i"}},
]},
(err, docs)=>{docs.toArray((err, res)=>{
count= res.length
})}
)
.skip(0).limit(10).toArray((err, docs)=>{
res = {data:docs, dataLength:count }
cb(err, res);
// })
});
I am getting this err: TypeError: Cannot read property 'skip' of undefined