- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章mongodb与mysql命令详细对比由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
传统的关系数据库一般由数据库(database)、表(table)、记录(record)三个层次概念组成,MongoDB是由数据库(database)、集合(collection)、文档对象(document)三个层次组成。MongoDB对于关系型数据库里的表,但是集合中没有列、行和关系概念,这体现了模式自由的特点.
MySQL 。 |
MongoDB 。 |
说明 。 |
mysqld 。 |
mongod 。 |
服务器守护进程 。 |
mysql 。 |
mongo 。 |
客户端工具 。 |
mysqldump 。 |
mongodump 。 |
逻辑备份工具 。 |
mysql 。 |
mongorestore 。 |
逻辑恢复工具 。 |
。 |
db.repairDatabase() 。 |
修复数据库 。 |
mysqldump 。 |
mongoexport 。 |
数据导出工具 。 |
source 。 |
mongoimport 。 |
数据导入工具 。 |
grant * privileges on *.* to … 。 |
Db.addUser() 。 Db.auth() 。 |
新建用户并权限 。 |
show databases 。 |
show dbs 。 |
显示库列表 。 |
Show tables 。 |
Show collections 。 |
显示表列表 。 |
Show slave status 。 |
Rs.status 。 |
查询主从状态 。 |
Create table users(a int, b int) 。 |
db.createCollection("mycoll", {capped:true. size:100000}) 另:可隐式创建表. |
创建表 。 |
Create INDEX idxname ON users(name) 。 |
db.users.ensureIndex({name:1}) 。 |
创建索引 。 |
Create INDEX idxname ON users(name,ts DESC) 。 |
db.users.ensureIndex({name:1,ts:-1}) 。 |
创建索引 。 |
Insert into users values(1, 1) 。 |
db.users.insert({a:1, b:1}) 。 |
插入记录 。 |
Select a, b from users 。 |
db.users.find({},{a:1, b:1}) 。 |
查询表 。 |
Select * from users 。 |
db.users.find() 。 |
查询表 。 |
Select * from users where age=33 。 |
db.users.find({age:33}) 。 |
条件查询 。 |
Select a, b from users where age=33 。 |
db.users.find({age:33},{a:1, b:1}) 。 |
条件查询 。 |
select * from users where age<33 。 |
db.users.find({'age':{$lt:33}}) 。 |
条件查询 。 |
select * from users where age>33 and age<=40 。 |
db.users.find({'age':{$gt:33,$lte:40}}) 。 |
条件查询 。 |
select * from users where a=1 and b='q' 。 |
db.users.find({a:1,b:'q'}) 。 |
条件查询 。 |
select * from users where a=1 or b=2 。 |
db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } ) 。 |
条件查询 。 |
select * from users limit 1 。 |
db.users.findOne() 。 |
条件查询 。 |
select * from users where name like "%Joe%" 。 |
db.users.find({name:/Joe/}) 。 |
模糊查询 。 |
select * from users where name like "Joe%" 。 |
db.users.find({name:/^Joe/}) 。 |
模糊查询 。 |
select count(1) from users 。 |
Db.users.count() 。 |
获取表记录数 。 |
select count(1) from users where age>30 。 |
db.users.find({age: {'$gt': 30}}).count() 。 |
获取表记录数 。 |
select DISTINCT last_name from users 。 |
db.users.distinct('last_name') 。 |
去掉重复值 。 |
select * from users ORDER BY name 。 |
db.users.find().sort({name:-1}) 。 |
排序 。 |
select * from users ORDER BY name DESC 。 |
db.users.find().sort({name:-1}) 。 |
排序 。 |
EXPLAIN select * from users where z=3 。 |
db.users.find({z:3}).explain() 。 |
获取存储路径 。 |
update users set a=1 where b='q' 。 |
db.users.update({b:'q'}, {$set:{a:1}}, false, true) 。 |
更新记录 。 |
update users set a=a+2 where b='q' 。 |
db.users.update({b:'q'}, {$inc:{a:2}}, false, true) 。 |
更新记录 。 |
delete from users where z="abc" 。 |
db.users.remove({z:'abc'}) 。 |
删除记录 。 |
。 |
db. users.remove() 。 |
删除所有的记录 。 |
drop database IF EXISTS test, |
use test 。 db.dropDatabase() 。 |
删除数据库 。 |
drop table IF EXISTS test, |
db.mytable.drop() 。 |
删除表/collection 。 |
。 |
db.addUser(‘test', 'test') 。 |
添加用户 。 readOnly-->false 。 |
。 |
db.addUser(‘test', 'test', true) 。 |
添加用户 。 readOnly-->true 。 |
。 |
db.addUser("test","test222") 。 |
更改密码 。 |
。 |
db.system.users.remove({user:"test"}) 。 或者db.removeUser('test') 。 |
删除用户 。 |
。 |
use admin 。 |
超级用户 。 |
。 |
db.auth(‘test', ‘test') 。 |
用户授权 。 |
。 |
db.system.users.find() 。 |
查看用户列表 。 |
。 |
show users 。 |
查看所有用户 。 |
。 |
db.printCollectionStats() 。 |
查看各collection的状态 。 |
。 |
db.printReplicationInfo() 。 |
查看主从复制状态 。 |
。 |
show profile 。 |
查看profiling 。 |
。 |
db.copyDatabase('mail_addr','mail_addr_tmp') 。 |
拷贝数据库 。 |
。 |
db.users.dataSize() 。 |
查看collection数据的大小 。 |
。 |
db. users.totalIndexSize() 。 |
查询索引的大小 。 |
。
mongodb语法 MongoDB的好处挺多的,比如多列索引,查询时可以用一些统计函数,支持多条件查询,但是目前多表查询是不支持的,可以想办法通过数据冗余来解决多表查询的问题。 MongoDB对数据的操作很丰富,下面做一些举例说明,内容大部分来自官方文档,另外有部分为自己理解。 查询colls所有数据 db.colls.find() //select * from colls 通过指定条件查询 db.colls.find({‘last_name': ‘Smith'});//select * from colls where last_name='Smith' 指定多条件查询 db.colls.find( { x : 3, y : “foo” } );//select * from colls where x=3 and y='foo' 指定条件范围查询 db.colls.find({j: {$ne: 3}, k: {$gt: 10} });//select * from colls where j!=3 and k>10 查询不包括某内容 db.colls.find({}, {a:0});//查询除a为0外的所有数据 支持<, <=, >, >=查询,需用符号替代分别为$lt,$lte,$gt,$gte db.colls.find({ “field” : { $gt: value } } ); db.colls.find({ “field” : { $lt: value } } ); db.colls.find({ “field” : { $gte: value } } ); db.colls.find({ “field” : { $lte: value } } ); 也可对某一字段做范围查询 db.colls.find({ “field” : { $gt: value1, $lt: value2 } } ); 不等于查询用字符$ne db.colls.find( { x : { $ne : 3 } } ); in查询用字符$in db.colls.find( { “field” : { $in : array } } ); db.colls.find({j:{$in: [2,4,6]}}); not in查询用字符$nin db.colls.find({j:{$nin: [2,4,6]}}); 取模查询用字符$mod db.colls.find( { a : { $mod : [ 10 , 1 ] } } )// where a % 10 == 1 $all查询 db.colls.find( { a: { $all: [ 2, 3 ] } } );//指定a满足数组中任意值时 $size查询 db.colls.find( { a : { $size: 1 } } );//对对象的数量查询,此查询查询a的子对象数目为1的记录 $exists查询 db.colls.find( { a : { $exists : true } } ); // 存在a对象的数据 db.colls.find( { a : { $exists : false } } ); // 不存在a对象的数据 $type查询$type值为bsonhttp://bsonspec.org/数 据的类型值 db.colls.find( { a : { $type : 2 } } ); // 匹配a为string类型数据 db.colls.find( { a : { $type : 16 } } ); // 匹配a为int类型数据 使用正则表达式匹配 db.colls.find( { name : /acme.*corp/i } );//类似于SQL中like 内嵌对象查询 db.colls.find( { “author.name” : “joe” } ); 1.3.3版本及更高版本包含$not查询 db.colls.find( { name : { $not : /acme.*corp/i } } ); db.colls.find( { a : { $not : { $mod : [ 10 , 1 ] } } } ); sort()排序 db.colls.find().sort( { ts : -1 } );//1为升序2为降序 limit()对限制查询数据返回个数 db.colls.find().limit(10) skip()跳过某些数据 db.colls.find().skip(10) snapshot()快照保证没有重复数据返回或对象丢失 count()统计查询对象个数 db.students.find({‘address.state' : ‘CA'}).count();//效率较高 db.students.find({‘address.state' : ‘CA'}).toArray().length;//效率很低 group()对查询结果分组和SQL中group by函数类似 distinct()返回不重复值 。
最后此篇关于mongodb与mysql命令详细对比的文章就讲到这里了,如果你想了解更多关于mongodb与mysql命令详细对比的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
目录 进程 其他相关概念 创建线程的两种方式 为什么使用start()方法而不直接使用run()方法 start()方法底层
CURL状态码列表 状态码 状态原因 解释 0 正常访问
ODBC连接类函数 odbc_connect函数:打开一个ODBC连接 odbc_close函数:关闭一个已经打开的ODBC连接 odbc_close_all函数:关闭所有已经打开的ODBC连
作为标题,如何计算从纪元1900到现在使用boost的持续时间? 编辑:很抱歉以前的问题太短。我将再次描述我的问题。 我有关于将生日另存为整数的问题。我创建了四个函数,用法如下: ptime转换为整数
前言 在Java中,有一个常被忽略 但 非常重要的关键字Synchronized今天,我将详细讲解 Java关键字Synchronized的所有知识,希望你们会喜欢 目录 1. 定义 J
详细 JVM 垃圾收集日志的时间戳是收集的开始还是结束? 2016-08-09T21:04:19.756-0400: 224890.317: [GC Desired survivor size 167
我在“Master-Detail”概念上苦苦挣扎,除了一点点(但很重要)的细微差别外,几乎所有东西都按预期工作。我应该在 Storyboard上更改什么以在详细信息 View (屏幕截图底部的右上角)
我希望能够显示表格的详细 View ,但不推送新屏幕,而只显示表格所在的详细 View 。 设置它的最佳方式是什么......如果真的可行的话? ---------------------------
我在我的博客中为我的帖子使用了详细 View ,每篇帖子都有评论,所以我想对它们进行分页,但我不知道该怎么做,因为我请求了帖子模型。我知道如何在功能 View 中执行此操作,但不知道如何在详细 Vie
在下面的代码中,与 pm 对齐,该行是否会 move 整个内存并将其分配给 pm,或者它只会 move p 指向的内存而不是整个数组? int main() { int*
1·下载 https://dev.mysql.com/downloads/mysql/ 2·安装服务 1)管理员运行cmd 2)D: 3)cd D:\mysql
今天以前一直用的SQL Server 2005做开发,偶尔也用MySQL,现入手公司项目,用到SQL Server 2008,于是乎必须安装它,免得出现其他很纠结的小问题,现将自己安装图解分享如下:
1. crontab命令选项 复制代码 代码如下: #crontab -u <-l, -r, -e> -u指定一个用
我们有一个 WPF 应用程序,它有一个主窗口/详细信息窗口,两者都是 WPF 数据网格。当您在上部数据网格中选择一行时,详细信息将显示在下部数据网格中。我想知道从 UI 的角度来看是否有任何关于如何处
在可视化 Perforce 客户端 (p4v) 中有一个选项: 显示文件操作的 p4 命令输出 启用后,在日志 Pane 中,我可以看到这样的详细日志记录: p4 sync /Users/az/ftp
在其他服务器上设置测试环境后,在几个API调用中出现错误。 99%肯定这是MySQL的事情,但是返回的错误根本没有帮助: global name 'sys' is not defined" 我已经导入
我正在维护一个通用的 iOS 应用程序,其开发已开始于 iOS 6。我正在为 iOS 7 更新 UI。现在我遇到了应用程序的 iPad 部分的奇怪问题。这部分遵循使用 UISplitViewContr
我希望我能正确描述这种情况。当它发生时很容易在屏幕上看到,但很难用语言解释,但我会尽力而为。 我有一个带有固定主视图 (UITableView) 和两个详细 View 之一的 UISplitViewC
我尝试在 eclipse 和 intelliJ 参数中使用垃圾收集记录器来配置简单的测试程序。尝试了不同类型的配置,但尚未创建日志文件。 -XX:+PrintGCDetails -XX:+PrintG
正如您所知,.cap 文件中的 java 小程序的输出文件格式必须通过智能卡读卡器/写卡器(如 ACR122 或任何其他读卡器)部署到 java 卡,而且我相信 java 卡与 java 卡之间的部署
我是一名优秀的程序员,十分优秀!