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 ...
随机推荐
- ng-option
select 是 AngularJS 预设的一组directive.下面是其官网api doc给出的用法:AngularJS:select 大意是,select中的ngOption可以采用和ngRep ...
- HTTP 和 HTTPS
一.HTTP协议 最近看了一些网络通信方面的书籍,研究了一下 HTTP 和 TCP/IP,有了一些新的收获和理解,在这里做个归纳和总结. (1)什么是HTTP协议 HTTP (HyperText Tr ...
- Unix Shortcuts
find . -name "*.java" -type f find all the files within a director and its sub-directory e ...
- 第 9 章 MySQL数据库Schema设计的性能优化
前言: 很多人都认为性能是在通过编写代码(程序代码或者是数据库代码)的过程中优化出来的,其实这是一个非常大的误区.真正影响性能最大的部分是在设计中就已经产生了的,后期的优化很多时候所能够带来的改善都只 ...
- 三、 添加视图View(ASP.NET MVC5 系列)
在这一章节我们可以修改HelloWorldController类,通过使用视图模板来封装处理产生给客户端的HTML响应. 我们将使用Razor View engine来创建视图文件.基于Razor的视 ...
- IT培训行业揭秘(六)
2017年全国的IT职业培训机构的招生数量相比于去年同期都出现了大规模的下滑,虽然目前大学生毕业之后参加培训班的人数依然没有变化,但是目前中小培训机构像雨后春笋般的纷纷建立,他们纷纷抢占市场,为了招生 ...
- kafka 0.10.2 解决java无法生产消息到指定topic问题
主要是修改server.properties的advertised.listeners advertised.listeners=PLAINTEXT://192.168.59.132:9092
- JDFS:一款分布式文件管理实用程序第二篇(更新升级、解决一些bug)
一 前言 本文是<JDFS:一款分布式文件管理实用程序>系列博客的第二篇,在上一篇博客中,笔者向读者展示了JDFS的核心功能部分,包括:服务端与客户端部分的上传.下载功能的实现,epoll ...
- C#中的委托(一)
一.委托 把方法作为参数传给其他方法: 二.声明委托 在C#中使用一个类时,分两个阶段.首先,需要去定义一个类,然后实例化类的一个对象(只需要静态方法除外). 使用委托也需要经过这2个步骤,首先必须定 ...
- 汽车Vin码识别——可以嵌入到手机里的新OCR识别技术
汽车Vin码识别(车架号识别),顾名思义,就是识别汽车的Vin码(车架号),汽车Vin码识别(车架号识别)利用的是OCR识别技术,支持视频流获取图像,自动触发识别,另外汽车Vin码 ...