[译]Mongoose指南 - 查询
2024-10-18 22:29:02
查询有带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);
最新文章
- Warning: Using a password on the command line interface can be insecure.解决办法
- 深入了解 JavaScript 中的 for 循环
- CXF:通过WebService上传文件,包括大文件的处理
- 响应式布局susy框架之入门学习篇
- 比较escape、encodeURI、encodeURIComponent
- 为什么要在<;button>;元素中添加type属性
- thinkphp 调用函数
- Java基础知识强化08:将字符串倒序输出(包括空格)的几种方法
- C#入门经典第七章,错误调试
- scala for spark
- shell 常用命令语法简介
- python 面试小基础
- MFC/VC CxImage 编译问题 (VS2013)
- Python -- tabulate 模块,
- 【UER #1】DZY Loves Graph(待卡常数)
- 使用 Swagger UI 与 Swashbuckle 创建 RESTful Web API 帮助文件(转)
- Android 监听手机GPS打开状态
- 团队项目个人进展——Day09
- java并发基础(三)--- 任务执行
- .net修炼笔记
热门文章
- bzoj2819 Nim
- ecshop /includes/init.php Arbitrary User Login Vul
- Objective-C 谈谈深浅拷贝,copy和mutable copy都不是完全拷贝
- AngularJs form.FormController、ngModel.NgModelController
- CF 405C Unusual Product(想法题)
- 使用uWSGI部署django项目
- MyBatis详解 与配置MyBatis+Spring+MySql
- CF715C:Digit Tree
- javascript之标识(zhi)符、关键字与保留字
- 逐行读取txt文件