Mongoose 互动版

##查询

上节课程里集合已经创建成功,我们就先来进行第一步操作 —— 查询。

查询分很多种类型,如条件查询,过滤查询等等,今天我们只学习最基本的find查询,在后面的学习中,我们会专门针对查询做详细的介绍,好,我们就先来学习使用find查询。

1.find查询: obj.find(查询条件,callback);

Model.find({},function(error,docs){
   //若没有向find传递参数,默认的是显示所有文档
});

Model.find({ "age": 28 }, function (error, docs) {
  if(error){
    console.log("error :" + error);
  }else{
    console.log(docs); //docs: age为28的所有文档
  }
}); 
参考示例,查询全部文档并console输出所有结果?
TestModel.find({}, function(error, docs) {
    console.log(docs);
});