mongodb数据库查询语句(php操作mongoDB数据库查询的时候怎样写“或”这样的多个条件查询代码)
本文目录
- php操作mongoDB数据库查询的时候怎样写“或”这样的多个条件查询代码
- mongodb数据库如何查询某个字段的最大值
- mongodb 带点的列名查询
- python3 mongodb怎么实现关联查询
- 怎么使用python编写根据输入查询条件查询mongoDB数据库
- mongodb isodate怎么查询
- mongodb查询数据库有哪些表
- mongodb 命令行用什么命令查询Collection文档结构
php操作mongoDB数据库查询的时候怎样写“或”这样的多个条件查询代码
据我所知,目前mongoDB没有“或”这个东西
但我刚才在网上查了下
发现了下面的信息,你参考下吧
在mongodb中有$or 操作符的,官网中给出的例子如下:
Simple:
db.foo.find( { $or : } )
With another field
db.foo.find( { name : "bob" , $or : } )
The $or operator retrieves matches for each or clause individually and eliminates duplicates when returning results. A number of $or optimizati*** are planned for 1.8. See this thread for details.
$or cannot be nested.
mongodb数据库如何查询某个字段的最大值
1、select distinct(类型 ),(select max(单价) from table where 类型 =c.类型 ) from table c。
2、举例:
person: {
// ...
name: ’A’
did: ’buy a dog’};
person: {
// ...
name: ’B’}。
3、相关用法
1)# 进入数据库 admin
use admin
2)# 增加或修改用户密码(3.0版本用creatuser)
db.addUser(’name’,’pwd’)
3)# 查看用户列表
db.system.users.find()
4) # 用户认证
db.auth(’name’,’pwd’)
5)# 删除用户
db.removeUser(’name’)
6) # 查看所有用户
show users
7)# 查看所有数据库
show dbs
8)# 查看所有的 collection
show collecti***
9)# 查看各 collection 的状态
db.printCollectionStats()
10)# 查看主从复制状态
db.printReplicationInfo()
mongodb 带点的列名查询
mongodb中使用aggregate可以返回数组字段数组的指定索引的元素
参考语句:
{$project:{"blog1":1}},
{$unwind:"$blog1"},
{$match:{’blog1.uidd’:666}},
{$group:{_id:"$_id","blog":{$push:"$blog1"}}}
{$project:{"$text":1}},
python3 mongodb怎么实现关联查询
MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可护展的高性能数据存储解决方案。它的特点是高性能、易部署、易使用,存储数据非常方便。
MongoDB 简单使用
联接数据库
复制代码代码如下:
In : import pymongo
In : from pymongo import Connection
In : connection = Connection(’192.168.1.3’, 27017) //创建联接
Connection 相关参数
复制代码代码如下:
Connection()
数据库操作
复制代码代码如下:
In : c.database_names() //列出所有数据库名称
Out
In : c.server_info() //查看服务器相关信息
Out:
{u’bits’: 64,
u’gitVersion’: u’nogitversion’,
u’ok’: 1.0,
u’sysInfo’: u’Linux yellow 2.6.24-27-server #1 SMP Fri Mar 12 01:23:09 UTC 2010 x86_64 BOOST_LIB_VERSION=1_40’,
u’version’: u’1.2.2’}
In //选择数据库
In : db.collection_names() //列出当前数据库中所有集合名称
Out
In : db.connection //查看联接信息
Out: Connection(’192.168.1.3’, 27017)
In : db.create_collection(’test_abeen’) //创建新集合
Out: Collection(Database(Connection(’192.168.1.3’, 27017), u’test’), u’test_abeen’)
In : db.last_status() //查看上次操作状态
Out: {u’err’: None, u’n’: 0, u’ok’: 1.0}
In : db.name //查看当前数据库名称
Out: u’test’
In : db.profiling_info() //查看配置信息
Out
In : db.profiling_level()
Out: 0.0
集合操作
复制代码代码如下:
In : db.collection_names() //查看当前数据库所有集合名称
Out:
[u’system.indexes’,
u’fs.files’,
u’fs.chunks’,
u’test_gao’,
u’system.users’,
u’test_abeen’]
In : c = db.test_abeen //选择集合
In : c.name //查看当前集合名称
Out: u’test_abeen’
In : c.full_name //查看当前集合全名
Out: u’test.test_abeen’
In : c.database //查看当前集合数据库相关信息
Out: Database(Connection(’192.168.1.3’, 27017), u’test’)
In : post = {"author":"Mike","text":"this is a test by abeen"}
In : posts = db.posts
In : posts.insert(post) //向数据库集合插入文档,默认创建集合
Out: ObjectId(’4c358492421aa91e70000000’)
In : db.collection_names() //显示所有集合名称
Out:
[u’system.indexes’,
u’fs.files’,
u’fs.chunks’,
u’test_gao’,
u’system.users’,
u’test_abeen’,
u’posts’]
In : posts.find_one() //从集合查找信息
Out:
{u’_id’: ObjectId(’4c358492421aa91e70000000’),
u’author’: u’Mike’,
u’text’: u’this is a test by abeen’}
In : p.update({"author":"Mike"},{"$set":{"author":"abeen","text":"this is a test by abeen shan shan"}})//更新集合文档信息
In : list(p.find())
Out:
[{u’_id’: ObjectId(’4c358492421aa91e70000000’),
u’author’: u’abeen’,
u’text’: u’this is a test by abeen shan shan’}]
In : list(posts.find())
Out:
[{u’_id’: ObjectId(’4c358492421aa91e70000000’),
u’author’: u’Mike’,
u’text’: u’this is a test by abeen’},
{u’_id’: ObjectId(’4c358ad4421aa91e70000002’), u’a’: u’aa’, u’b’: u’bb’},
{u’_id’: ObjectId(’4c358ad9421aa91e70000003’), u’a’: u’aa’, u’b’: u’bb’},
{u’_id’: ObjectId(’4c358abb421aa91e70000001’),
u’a’: u’abeen’,
u’b’: u’this bb is updated’}]
In : posts.remove({"a":"abeen"}) //删除符合条件的文档
In : list(posts.find())
Out:
[{u’_id’: ObjectId(’4c358492421aa91e70000000’),
u’author’: u’Mike’,
u’text’: u’this is a test by abeen’},
{u’_id’: ObjectId(’4c358ad4421aa91e70000002’), u’a’: u’aa’, u’b’: u’bb’},
{u’_id’: ObjectId(’4c358ad9421aa91e70000003’), u’a’: u’aa’, u’b’: u’bb’}]
In : db.collection_names()
Out:
[u’system.indexes’,
u’fs.files’,
u’fs.chunks’,
u’test_gao’,
u’system.users’,
u’test_abeen’,
u’posts’,
u’doc_abeen’]
In : db.drop_collection("doc_abeen") //删除集合
In : db.collection_names()
Out:
[u’system.indexes’,
u’fs.files’,
u’fs.chunks’,
u’test_gao’,
u’system.users’,
u’test_abeen’,
u’posts’]
代码
复制代码代码如下:
In : result = db.posts.find({"a":"aa"})//查找
In : type(result)
Out: 《class ’pymongo.cursor.Cursor’》
In : list(result)
Out:
[{u’_id’: ObjectId(’4c358ad4421aa91e70000002’), u’a’: u’aa’, u’b’: u’bb’},
{u’_id’: ObjectId(’4c358ad9421aa91e70000003’), u’a’: u’aa’, u’b’: u’bb’}]
find格式
复制代码代码如下:
find()
代码
复制代码代码如下:
In : db.posts.count()//当前集合文档数
Out: 3
In : type(db.posts)
Out: 《class ’pymongo.collection.Collection’》
In : posts.rename(’test_abeen’)//重命名当前集合
In : db.collection_names()
Out:
[u’system.indexes’,
u’fs.files’,
u’fs.chunks’,
u’test_gao’,
u’system.users’,
u’test_abeen’]
In : for post in c.find({"a":"aa"}).sort("a"): //查询并排序列
post
Out: {u’_id’: ObjectId(’4c358ad4421aa91e70000002’), u’a’: u’aa’, u’b’: u’bb’}
Out: {u’_id’: ObjectId(’4c358ad9421aa91e70000003’), u’a’: u’aa’, u’b’: u’bb’}
复制代码代码如下:
》 db.foo.insert( { x : 1, y : 1 } )
》 db.foo.insert( { x : 2, y : "string" } )
》 db.foo.insert( { x : 3, y : null } )
》 db.foo.insert( { x : 4 } )
// Query #1 y 为null或不存在
》 db.foo.find( { "y" : null } )
{ "_id" : ObjectId("4dc1975312c677fc83b5629f"), "x" : 3, "y" : null }
{ "_id" : ObjectId("4dc1975a12c677fc83b562a0"), "x" : 4 }
// Query #2 y为null的值
》 db.foo.find( { "y" : { $type : 10 } } )
{ "_id" : ObjectId("4dc1975312c677fc83b5629f"), "x" : 3, "y" : null }
// Query #3 y不存在的结果
》 db.foo.find( { "y" : { $exists : false } } )
{ "_id" : ObjectId("4dc1975a12c677fc83b562a0"), "x" : 4 }
怎么使用python编写根据输入查询条件查询mongoDB数据库
hid=239526
cur = my_set.find({"sourceID":1,"downloadDate":"2018-05-08","bwHotelID":hid},{"checkIn":1,"_id":0}).sort()
查询条件参数化, 这里是josn格式,不是这字符串,不用占位符之类的东西
你要知道json对象就等同于你的python代码
你在它那直接用变量代替就行
mongodb isodate怎么查询
问题:
1,ISODate("2016-01-01T00:00:00Z"),这个是什么日期格式。
2,mongo vue的时间类型属性的相关查询。包括,大于某个时间,小于某个时间,在某一段时间范围。
3,了解一下mongo数据库中存储时间Date类型数据的秘密。
MongoDB 日期查询目前可通过Date 和ISODate两种方式:
1.Date方式。
例如startDate《=2012.12.7且endDate》=2012.12.7:可翻译为
"startDate":{$lte:new Date(2012,11,7)},"endDate":{$gte:new Date(2012,11,7)}。
如下是查询日期大于等于2016年12月1日的记录条数(注意,中间的月份写11,就是12月)
db.xxx.find({"updateTime" : {$gte:new Date(2016,11,1)}})
看下图,发现,mongo vue自动给日期转换为ISODate的格式了。
mongodb查询数据库有哪些表
db.foo.find(...).count()
db.foo.find(...).limit(n) 根据条件查找数据并返回指定记录数
db.foo.find(...).skip(n)
db.foo.find(...).sort(...) 查找排序
db.foo.findOne() 根据条件查询只查询一条数据
db.foo.getDB() get DB object associated with collection 返回表所属的库
db.foo.getIndexes() 显示表的所有索引
db.foo.group( { key : ..., initial: ..., reduce : ... } ) 根据条件分组
db.foo.mapReduce( mapFunction , reduceFunction , 《optional params》 )
db.foo.remove(query) 根据条件删除数据
db.foo.renameCollection( newName ) renames the collection 重命名表
db.foo.save(obj) 保存数据
db.foo.stats() 查看表的状态
db.foo.storageSize() - includes **** space allocated to this collection 查询分配到表空间大小
db.foo.totalIndexSize() - size in bytes of all the indexes 查询所有索引的大小
db.foo.totalSize() - storage allocated for all data and indexes 查询表的总大小
db.foo.update(query, object) 根据条件更新数据
db.foo.validate() - SLOW 验证表的详细信息
db.foo.getShardVersion() - only for use with sharding
mongodb 命令行用什么命令查询Collection文档结构
成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作。
输入help可以看到基本操作命令:
show dbs:显示数据库列表
show collecti***:显示当前数据库中的集合(类似关系数据库中的表)
show users:显示用户!
更多文章:
表格trim函数(excel表格中卡号数字后面的空格怎么一起删除)
2026年3月27日 20:40
微信小程序商微信公众号制微信小程序开发制作(如何开发微信小程序微信宣传制作a)
2026年3月27日 19:40
this is me英语自我介绍小海报(this is me英语手抄报简单)
2026年3月27日 19:20
bigdecimal 除法(java中 BigDecimal的类型的除法)
2026年3月27日 17:40







