mongoose 查询

1. find 查询表中所有数据

 let data = await Model.find({})

2. findOne 查询表中一条数据

let data = await Model.findOne({ age: 16 })

3.1 count()  返回符合查询条件的数据的长度 

注: count() 方法将会在未来版本移除,请用count Documents()

let total = await Model.findOne({ age: 16}).count()

3.2 countDocuments()  返回符合查询条件的数据的长度 

let total = await Model.findOne({ age: 16 }).countDocuments()

3.3 estimatedDocumentCount()  忽略查询条件,返回表中所有数据的数目长度

let total = await Model.findOne({ age: 16}).estimatedDocumentCount()
原文地址:https://www.cnblogs.com/naturl/p/14673443.html