查询有带callback和不带callback两种方式

所有mongoose的callback都是这种格式: callback(err, result)

var Person = mongoose.model('Person', yourSchema);

Person.findOne({'name.last':'Ghost'}, 'name occupation', function(err, person){
if(err) return handleError(err);
console.log(person.name.first + ' ' + person.name.last + ' ' + person.occupation);
});

看看不带callback怎么查询

var query = Person.findOne({'name.last': 'Ghost'});

///只查找name和occupation字段
query.select('name occupation'); query.exec(function(err, person){
if(err) return handleError(err);
res.send(person);
}):

Query实例能使我们构造自己的查询

Person
.find({occupation: /host/})
.where('name.last').equal('Ghost')
.where('ag').gt(17).lt(66)
.limit(10)
.sort('-occupation')
.select('name occupation')
.exec(callback);

  

最新文章

  1. Warning: Using a password on the command line interface can be insecure.解决办法
  2. 深入了解 JavaScript 中的 for 循环
  3. CXF:通过WebService上传文件,包括大文件的处理
  4. 响应式布局susy框架之入门学习篇
  5. 比较escape、encodeURI、encodeURIComponent
  6. 为什么要在<button>元素中添加type属性
  7. thinkphp 调用函数
  8. Java基础知识强化08:将字符串倒序输出(包括空格)的几种方法
  9. C#入门经典第七章,错误调试
  10. scala for spark
  11. shell 常用命令语法简介
  12. python 面试小基础
  13. MFC/VC CxImage 编译问题 (VS2013)
  14. Python -- tabulate 模块,
  15. 【UER #1】DZY Loves Graph(待卡常数)
  16. 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件(转)
  17. Android 监听手机GPS打开状态
  18. 团队项目个人进展——Day09
  19. java并发基础(三)--- 任务执行
  20. .net修炼笔记

热门文章

  1. bzoj2819 Nim
  2. ecshop /includes/init.php Arbitrary User Login Vul
  3. Objective-C 谈谈深浅拷贝,copy和mutable copy都不是完全拷贝
  4. AngularJs form.FormController、ngModel.NgModelController
  5. CF 405C Unusual Product(想法题)
  6. 使用uWSGI部署django项目
  7. MyBatis详解 与配置MyBatis+Spring+MySql
  8. CF715C:Digit Tree
  9. javascript之标识(zhi)符、关键字与保留字
  10. 逐行读取txt文件