nodejs mongodb 查询要看的文章
http://www.cnblogs.com/refactor/archive/2012/07/30/2591344.html
数组很大多数情况下可以这样理解:每一个元素都是整个键的值.
db.users.findOne({"userName":"wyx","emails":"bbb@qq.com"})能匹配到
{
userName: 'wyx',
emails:[
'aaa@qq.com',
'bbb@qq.com',
'ccc@qq.com'
]
}
MongoDB高级查询
http://www.nonb.cn/blog/mongodb-advanced-queries.html
Node+Mongoose常用查询中文文档
http://www.nonb.cn/blog/nodejs-mongoose-query-chinaese.html
推荐看这三篇 mongodb的查询,以及nodejs和mongoose联用的情况
看完mongoose的基本查询就没问题了
如何在mongodb中使用索引?
http://www.cnblogs.com/huangxincheng/archive/2012/02/29/2372699.html
MongoDB组合索引的优化
非常好的文章,将索引,排序等问题的性能优劣取舍讲的很透彻
http://www.csdn.net/article/2012-11-09/2811690-optimizing-mongodb-compound
explain方法若出现BasicCursor可以视为警告,它意味着MongoDB将对数据集做一个完全的扫描。当数据集里包含上千万条信息时,这完全是行不通的。因此要考虑加上适当的索引
常用的关键字, count, distinct, group ....
http://www.cnblogs.com/huangxincheng/archive/2012/02/21/2361205.html
mongoose中的2中操作方法,
callback and query returned
http://mongoosejs.com/docs/queries.html
Queries
Documents can be retrieved through several static helper methods of models.
Any model method which involves specifying query conditions can be executed two ways:
When a callback
function:
- is passed, the operation will be executed immediately with the results passed to the callback.
- is not passed, an instance of Query is returned, which provides a special
QueryBuilder
interface for you.
Let's take a look at what happens when passing a callback
:
var Person = mongoose.model('Person', yourSchema); // Query
// find each person with a last name matching 'Ghost', selecting the `name` and `occupation` fields
Person.findOne({ 'name.last': 'Ghost' }, 'name occupation', function (err, person) {
if (err) return handleError(err);
console.log('%s %s is a %s.', person.name.first, person.name.last, person.occupation) // Space Ghost is a talk show host.
})
Here we see that the query was executed immediately and the results passed to our callback. All callbacks in Mongoose use the pattern: callback(error, result)
. If an error occurs executing the query, the error
parameter will contain an error document, and result
will be null. If the query is successful, the error
parameter will be null, and the result
will be populated with the results of the query.
Anywhere a callback is passed to a function in Mongoose, the callback follows the patterncallback(error, results)
.
Now let's look at what happens when no callback
is passed:
// find each person with a last name matching 'Ghost'
var query = Person.findOne({ 'name.last': 'Ghost' });
// selecting the `name` and `occupation` fields
query.select('name occupation');
// execute the query at a later time
query.exec(function (err, person) {
if (err) return handleError(err);
console.log('%s %s is a %s.', person.name.first, person.name.last, person.occupation) // Space Ghost is a talk show host.
})
An instance of Query was returned which allows us to build up our query. Taking this example further:
Person
.find({ occupation: /host/ })
.where('name.last').equals('Ghost')
.where('age').gt(17).lt(66)
.where('likes').in(['vaporizing', 'talking'])
.limit(10)
.sort('-occupation')
.select('name occupation')
.exec(callback);
nodejs mongodb 查询要看的文章的更多相关文章
- mongodb查询之从多种分类中获取各分类最新一条记录
mongodb查询之从多种分类中获取各分类最新一条记录 2017年04月06日 13:02:47 monkey_four 阅读数:6707更多 个人分类: MongoDBJavaScript 文章 ...
- MongoDB查询操作限制返回字段的方法
这篇文章主要介绍了MongoDB查询操作限制返回字段的方法,需要的朋友可以参考下 映射(projection )声明用来限制所有查询匹配文档的返回字段.projection以文档的形式列举结果集中 ...
- react+react-router+react-redux+nodejs+mongodb项目
一个实际项目(OA系统)中的部分功能.这个demo中引入了数据库,数据库使用了mongodb.安装mongodb才能运行完整的功能.要看完整的项目可以移步我的github 技术栈 React v15. ...
- MongoDb进阶实践之六 MongoDB查询命令详述(补充)
一.引言 上一篇文章我们已经介绍了MongoDB数据库的查询操作,但是并没有介绍全,随着自己的学习的深入,对查询又有了新的东西,决定补充进来.如果大家想看上一篇有关MongoDB查询的 ...
- Spring Boot MongoDB 查询操作 (BasicQuery ,BSON)
MongoDB 查询有四种方式:Query,TextQuery,BasicQuery 和 Bson ,网上太多关于 Query 的查询方式,本文只记录 BasicQuery和Bson 的方式,Basi ...
- nodejs mongodb 数据库封装DB类 -转
使用到了nodejs的插件mongoose,用mongoose操作mongodb其实蛮方便的. 关于mongoose的安装就是 npm install -g mongoose 这个DB类的数据库配置是 ...
- MongoDB查询修改操作语句命令大全
MongoDB查询更新操作语句命令大全 查询操作 1.条件操作符 <, <=, >, >= 这个操作符就不用多解释了,最常用也是最简单的db.collection.find({ ...
- mongodb查询速度慢是什么原因?
mongodb查询速度慢是什么原因? 通过mongodb客户端samus代码研究解决问题 最近有项目需要用到mongodb,于是在网上下载了mongodb的源码,根据示例写了测试代码, ...
- Nodejs+MongoDB+Bootstrap+esj搭建的个人简易博客
github:https://github.com/yehuimmd/myNodeBloy Nodejs+MongoDB+jQuery+Bootstrap-esj搭建的个人简易博客 主要功能 前台 : ...
随机推荐
- ES6+转ES5
npm init //创建package.json文件 下载转换babel库及其100+依赖 npm install babel-cli -D npm install babel-preset-env ...
- 2.2Python基础语法(二)之运算符
返回总目录 目录: 1.Python运算符的分类 2.算数运算符 3.复合运算符 4.比较运算符 5.逻辑运算符 (一)Python运算符的分类: (二)算数运算符: 注意下面三种算数符号: 1.** ...
- 小程序push数组,渲染不出来解决办法
1.在data中,定义一个空数组: zhou_time:[] 2.声明: var zhou_time = this.data.zhou_time; 3.PUSH赋值: zhou_time.push({ ...
- Python接口自动化--URL参数的编码和解码 6
# _*_ coding:utf-8 _*_ #python2 import urllib #有时,需要从上一个请求的url获取参数,传到下一个请求中,中文会显示为编码的形式,这时候就需要进行解码 u ...
- 线程同步方式之互斥量Mutex
互斥量和临界区非常相似,只有拥有了互斥对象的线程才可以访问共享资源,而互斥对象只有一个,因此可以保证同一时刻有且仅有一个线程可以访问共享资源,达到线程同步的目的. 互斥量相对于临界区更为高级,可以对互 ...
- [转]vue全面介绍--全家桶、项目实例
慢慢了解vue及其全家桶的过程 原文http://blog.csdn.net/zhenghao35791/article/details/67639415 简介 “简单却不失优雅,小巧而不乏大匠”. ...
- HTML5API之获取地理位置详解
在使用地理位置API之前先来了解一下什么是经度和纬度以及地理位置获取的原理 首先经度指的是南北极的连接线,纬度指的是东西的连接线 地理位置的获取原理是通过IP地址(基于ISP记录,能够知道这个IP地址 ...
- shiro实战系列(十二)之常用专业术语
请花 2 分钟来阅读和理解它——这很重要.真的.这里的术语和概念在文档的任何地方都被涉及到,它将在总体上 大大简化你对 Shiro 和安全的理解. 由于所使用的术语使得安全可能令人困惑.我们将通过 ...
- nginx配置收集
同个服务,分别读取不同借口 location /xibao/service_api/ { if ($request_uri ~ ^/xibao/(.*)) { set $xibao_data_url ...
- Android 在ScrollView中嵌入ViewPage后ViewPage不能很好的工作的问题解决
解决办法:重写ScrollView,如下代码所示: public class MyScrollView extends ScrollView{ private GestureDetector mGes ...