pouchdb-find( pouchdb查询扩展插件 ,便于查询)
pouchdb-find
环境搭建
下载lib
bower install pouchdb-find
引入js
<script src="pouchdb.js"></script>
<script src="pouchdb.find.js"></script>
使用
1.createIndex
db.createIndex({
index: {
fields: ['foo']
}
}).then(function (result) {
// yo, a result
}).catch(function (err) {
// ouch, an error
});
2.find
db.find({
selector: {name: 'Mario'},
fields: ['_id', 'name'],
sort: ['name']
}).then(function (result) {
// yo, a result
}).catch(function (err) {
// ouch, an error
});
demo
db.createIndex({
index: {fields: ['name']}
}).then(function () {
return db.find({
selector: {name: {$gt: null}},
sort: ['name']
});
});
example Result
{
"docs": [
{
"_id": "mario",
"name": "Mario"
}
]
}
find 查询语法
为了避免出现bug 在每个查询都添加_id: {$gte: null}
(可以设为null意外的值)
db.find({
selector: {
_id: {$gte: null},
name: {$eq: 'Mario'}
}
});
条件关键词解析
- $lt Match fields "less than" this one.
- $gt Match fields "greater than" this one.
- $lte Match fields "less than or equal to" this one.
- $gte Match fields "greater than or equal to" this one.
- $eq Match fields equal to this one.
- $ne Match fields not equal to this one.
- $exists True if the field should exist, false otherwise.
- $type One of: "null", "boolean", "number", "string", "array", or "object".
- $regex use RegExp
相等查询
//1.
db.find({
selector: {
_id: {$gte: null},
name: {$eq: 'Mario'}
}
});
//2.
db.find({
selector: {
_id: {$gte: null},
name: 'Mario'
}
});
多条件查询
//1.
db.find({
selector: {
_id: {$gte: null},
series: 'Mario',
debut: { $gt: 1990 }
}
});
//2.
db.find({
selector: {
$and: [
_id: {$gte: null},
{ series: 'Mario' },
{ debut: { $gt: 1990 } }
]
}
});
模糊查询$regex
var keyword = 'mik'
var regExp = new RegExp('.*' + keyword + '.*', 'i');
db.find({
selector:{
_id: {"$gte": "NOB", "$lte": 'NOE'},
name:{"$regex": regExp}
}
})
.then(function(result){
//do some thing
var results = result.docs;
})
pouchdb-find( pouchdb查询扩展插件 ,便于查询)的更多相关文章
- SubSonic3.0插件分页查询速度测试
使用SubSonic3.0一段时间了,一直都想找机会测试一下各种查询分页速度,对比一下插件的查询效率到底怎么样,所以昨天写好了测试程序,准备好1K.1W.10W.50W和100W记录的数据表,早上详细 ...
- Dapper 链式查询 扩展
Dapper 链式查询扩展 DapperSqlMaker Github地址:https://github.com/mumumutou/DapperSqlMaker 欢迎大佬加入 Demo: 查询 ...
- sql的行转列(PIVOT)与列转行(UNPIVOT) webapi 跨域问题 Dapper 链式查询 扩展 T4 代码生成 Demo (抽奖程序)
sql的行转列(PIVOT)与列转行(UNPIVOT) 在做数据统计的时候,行转列,列转行是经常碰到的问题.case when方式太麻烦了,而且可扩展性不强,可以使用 PIVOT,UNPIVOT比 ...
- MySQL -- 全文检索(查询扩展检索)
通常用在查询的关键词太短,用户需要隐含知识进行扩展.例如,查单词database时,用户可能还希望不仅仅包含database的文档,可能还指包含mysql.oracle.db2等单词.这时就需要查询扩 ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- Queryable查询扩展
/// <summary> /// 查询扩展 /// </summary> /// <typeparam name="T"></typep ...
- 16.AutoMapper 之可查询扩展(Queryable Extensions)
https://www.jianshu.com/p/4b23e94a7825 可查询扩展(Queryable Extensions) 当在像NHibernate或者Entity Framework之类 ...
- Elasticsearch使用系列-基本查询和聚合查询+sql插件
Elasticsearch使用系列-ES简介和环境搭建 Elasticsearch使用系列-ES增删查改基本操作+ik分词 Elasticsearch使用系列-基本查询和聚合查询+sql插件 Elas ...
- django----对model查询扩展
基于对象关联查询 一对多查询(Book--Publish): 正向查询,按字段: (从关联的表中查询) book_obj.publish : 与这本书关联的出版社对象 book_obj.publish ...
随机推荐
- 怎么在vue中使用less
最近使用vue2.0重构项目, 使用vue-cli脚手架构建, 采用webpack模板, 要在项目中使用less进行样式的编写 首先, 打开终端, 在当前项目目录下安装less npm install ...
- Linux Network Management
Linux网络管理 (YouTube视频教程) ISO/OSI七层模型 ISO: The International Organization for Standardization 国际标准化组织 ...
- nginx配置优化+负载均衡+动静分离详解
nginx配置如下: #指定nginx进程运行用户以及用户组user www www;#nginx要开启的进程数为8worker_processes 8;#全局错误日志文件#debug输出日志最为详细 ...
- Linux如何安装VMware Tools
第一步:安装VMware Tools 桌面上会出现一个光盘,并且会弹出一个框框,里面是VMware Tools的安装包,将其拖到桌面上 就像下面这样 进入终端,将文件拷贝到/tmp目录下面,并解压(也 ...
- 史诗手册!微信小程序新手自学入门宝典!
一.小程序官方指南 1:官方开发工具下载: https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/download.html?t=201714 0.12 ...
- javaWeb学习总结(7)-会话之session技术
什么是Session 使用Cookie和附加URL参数都可以将上一次请求的状态信息传递到下一次请求中,但是如果传递的状态信息较多,将极大降低网络传输效率和增大服务器端程序处理的难度. Session技 ...
- Git添加远程库和从远程库中获取(新手傻瓜式教学)
一. Git添加远程库 1.在本地新建一个文件夹,在该文件夹使用Git工具,运行$ git init,将该文件夹变为本地Git仓库,同时会生成一个隐藏的.git文件夹. 2.在该文件夹中用Not ...
- IT培训行业揭秘(六)
2017年全国的IT职业培训机构的招生数量相比于去年同期都出现了大规模的下滑,虽然目前大学生毕业之后参加培训班的人数依然没有变化,但是目前中小培训机构像雨后春笋般的纷纷建立,他们纷纷抢占市场,为了招生 ...
- 一天搞定CSS:表单(form)--20
1.表单标签 2.input标签属性与取值 代码演示 <!DOCTYPE html> <html> <head> <meta charset="UT ...
- opencv 删除二值化图像中面积较小的连通域
对于上图的二值化图像,要去除左下角和右上角的噪点,方法:使用opencv去掉黑色面积较小的连通域. 代码 CvSeq* contour = NULL; double minarea = 100.0; ...