problem description
I want to get the total number of entries matching the query condition, total. How can I get it better?
what I"m doing now is to set another layer of query on the outside, which I don"t think is good.
db.collection("netdatas").find(query).count().then(total=>{
db.collection("netdatas").find(query).sort(sort).skip((page - 1)*num).limit(num).toArray().then(docs=>{
ws.send(JSON.stringify({
cmd:"query_netdatas",
data:{
num,
page,
total,
records:docs
}
}))
})
})
I can use aggregation after taking a look, but I didn"t get it ~