Mongodb 学习笔记(一)
MongoDB 是一款开源、跨平台、分布式,具有大数据处理能力的文档存储数据库。在 2007 年由 MongoDB 软件公司开发完成,并实现全部代码源发展。目 前,该文档数据库被国内外众多知名网因所采纳,用于提高数据访问的处理速度 和大数据存储问题。
基本操作命令 :
show dbs : 显示所有数据库(空数据库不会显示)。
use dbname : 切换至 数据库 dbname。
db.stats() 显示 数据库状态
db.dropdatabase() 删除当前数据库。
db. getCollectionNames () 查看当前数据库下的所有集合的名称
show roles 查看当前数据库的用户角色权限及用户名/密码信息
增删改查:
插入:
db.student.insert({"name":"Jason","age":20}) student 为集合名称,如果没有该集合,会自动创建。
db.student.insert([{"name":"dalie","age":30},{"name":"sun","sex":"male"}]) 插入多条记录 。 同一个集合中的文档,key 不用保持一致。
document = {"name":"biao","age":12}
db.student.insert(document); 也可以用声明变量的方式 将文档插入集合中
db.student.insert([{"name":"wang","age":11},{"name":"goudan","age":1}],{ordered:true}) 顺序插入 ordered为true时,如存在主键冲突的数据,会导致全部插入失败,false时,除出错记录外,其他记录正常插入。
查询:
db.student.find() 列出该集合内所有文档。
db.student.find({"name":"Jason"}) 括号内 可以填写 匹配条件 类似于 sql 中where
db.student.fingOne() db.student.findOne({"name":"Jason"}) 列出集合内符合条件的第一条文档
db.student.find().pretty() 将结果 以优美的形式展示。
db.student.find({},{name:1,age:1,_id:0}).pretty() 可以设置要查询的key ,1显示,0不显示。
db.student.find().limit(2) 返回前两条文档
db.student.find().skip(2) 跳过前两条文档,显示 之后的所有文档。
db.student.find().skip(2).limit(1) 显示第三条文档。
db.student.find({name:{$in:["Mike","Jason"]}}) $in 实现 范围查询。$in 用于不同文档指定同一个 Key 进行或条件匹配, $or 可以指定多个 Key 或条件匹配。
db.student.find({$or:[{name:"Jason"},{age:12}]})

更新:
db.student.update({name:"Jason"},{$set:{age1:12}})
$set 更新要修改的字段 $unset 删除该字段 $rename 更改字段名 $inc 修改数值做加法运算。
db.collection.updateOne() 。与 update()唯一的 区别是命令语法里少了 一个 multi: <boolean>选项, 也就是 updateOne()只适用于符合条件的一条文档的修改任务。
db.collection.updateMany() 。与 update()唯一的区别是命令语法里少了 一个 multi: <boolean>选项, 也就是 updateMany()只适用于符合条件的多条文档的修改任务。
db.collection.replaceOne() 。与 update()的区别有两处, 一个没有 multi: <boolean> 选项;另外一个在第二个参数 Cupdate 的<update>)里不能有更新操作符。
删除:
db.student.remove("name":"Jason") 删除姓名为Jason的文档。
db.student.remove({}) 删除集合内所有文档,但如果要删除整个集合 db.student.drop() 效率更高,它会直接删掉集合及索引。
Mongodb 学习笔记(一)的更多相关文章
- MongoDB学习笔记系列
回到占占推荐博客索引 该来的总会来的,Ef,Redis,MVC甚至Sqlserver都有了自己的系列,MongoDB没有理由不去整理一下,这个系列都是平时在项目开发时总结出来的,希望可以为各位一些帮助 ...
- PHP操作MongoDB学习笔记
<?php/*** PHP操作MongoDB学习笔记*///*************************//** 连接MongoDB数据库 **////*************** ...
- MongoDB 学习笔记(原创)
MongoDB 学习笔记 mongodb 数据库 nosql 一.数据库的基本概念及操作 SQL术语/概念 MongoDB术语/概念 解释/说明 database database 数据库 table ...
- mongoDB 学习笔记纯干货(mongoose、增删改查、聚合、索引、连接、备份与恢复、监控等等)
最后更新时间:2017-07-13 11:10:49 原始文章链接:http://www.lovebxm.com/2017/07/13/mongodb_primer/ MongoDB - 简介 官网: ...
- MongoDB学习笔记(转)
MongoDB学习笔记(一) MongoDB介绍及安装MongoDB学习笔记(二) 通过samus驱动实现基本数据操作MongoDB学习笔记(三) 在MVC模式下通过Jqgrid表格操作MongoDB ...
- 【转】MongoDB学习笔记(查询)
原文地址 MongoDB学习笔记(查询) 基本查询: 构造查询数据. > db.test.findOne() { "_id" : ObjectId("4fd58ec ...
- MongoDB学习笔记(六)--复制集+sharding分片 && 总结
复制集+sharding分片 背景 主机 IP 服务及端口 Server A ...
- MongoDB学习笔记(五)--复制集 && sharding分片
主从复制 主从节点开启 主节 ...
- MongoDB学习笔记(四)--索引 && 性能优化
索引 基础索引 ...
- MongoDB学习笔记(三)--权限 && 导出导入备份恢复 && fsync和锁
权限 绑定内网I ...
随机推荐
- uniapp - 如何申请阿里云存储
长话短说,简略表述 1. 登录阿里云,选择 oos对象云存储 https://oss.console.aliyun.com/overview 2. 新建“Bucket”,名称是唯一的(建议用公司或者个 ...
- 数据库sql优化总结之5--数据库SQL优化大总结
数据库SQL优化大总结 小编最近几天一直未出新技术点,是因为小编在忙着总结整理数据库的一些优化方案,特此奉上,优化总结较多,建议分段去消化,一口吃不成pang(胖)纸 一.百万级数据库优化方案 1.对 ...
- 搭建redis cluster集群服务
redis 5.0以下为ruby编写,运行命令时需要安装ruby,而5.0以上则为c编写,可直接安装后运行.因此本文使用redis5.0.5 1.编写配置文件 在 /home 下新建 redis-cl ...
- ubuntu16上部署confluence-6.14.5的迁移
author:headsen chen date: 2019-10-18 15:02:06 notice :created by headsen chen himself and not al ...
- Android 解读Event和Main Log
1 Android P EventLogTags文件 Android P 9.0.0 所有EventLogTags文件List: system/bt/EventLogTags.logtags syst ...
- SpringBoot MAVEN编译报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:
参考了好几篇文章没搞定,直到查询错误关键字 An unknown compilation problem occurred 分别参考了以下博客: https://blog.csdn.net/fanre ...
- (转)关于sql和MySQL的语句执行顺序(必看!!!)
原文:https://blog.csdn.net/u014044812/article/details/51004754 https://blog.csdn.net/j080624/article/d ...
- html页面自适应宽度
html页面实现响应式的方式有很多,本篇介绍懒人必备一招见效的方法. 在head标签中加入 <meta name="viewport" content="width ...
- 3秒钟unittest入门使用
一:unittest跑起来 unittest使用,具体使用方式可以查看unittest官网,以下简单做个介绍,在工作中使用最多的 # 第一步: 创建unittest类,且一定要继承unittest.T ...
- [LeetCode] 111. Minimum Depth of Binary Tree 二叉树的最小深度
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...