码迷,mamicode.com
首页 > 数据库 > 详细

mongodb 查询

时间:2017-09-22 17:52:19      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:min   log   使用   god   mongod   val   logs   timestamp   java   

1、模糊查询

通过模糊查询,查找相关数据:
db.test.find({name:/joe/})    ---查询name字段含有joe的数据 等同于db.test.find({name:{$regex:‘joe‘}})
db.test.find({name:/joe/i})   加了i,那么就不会区分大小写,都会显示,等同于db.test.find({name:{$regex:‘joe‘,$options:‘i‘}})
db.test.find({name:/^joe/i})   ^匹配以joe开头的,而且不区分大小写

2、类型查询

 
$type使用:
> db.test.find({content:{$type:2}}) --显示content是string的数据
> db.test.find({content:{$type:1}})  --显示content为double类型的
下面给出mongodb基于bson类型的列表:
Type DescriptionType value
Double 1
String 2
Object 3
Array 4
Binary data 5
Object id 7
Boolean 8
Date 9
Null 10
Regular expression 11
JavaScript code 13
Symbol 14
JavaScript code with scope 15
32-bit integer 16
Timestamp 17
64-bit integer 18
Min key 255
Max key 127

3、条件查询

根据以下数据

db.dev.find({"dev":"测试"})

技术分享

 4、只显示vdev.channels.1下的所有字段

 

mongodb 查询

标签:min   log   使用   god   mongod   val   logs   timestamp   java   

原文地址:http://www.cnblogs.com/michellexiaoqi/p/7575591.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!