mongo shell是一个MongoDB的交互式JavaScript接口。您可以使用mongo shell来查询和更新数据以及执行管理操作。

本篇经验将和大家介绍Mongo Shell的使用方法,希望对大家的工作和学习有所帮助!

方法/步骤

 
  1.  

    打开cmd命令行,输入mongo,就可以进入mongo Shell,如下图所示:

  2.  

    输入cls命令清屏,开始常用命令体验,如下图所示:

  3.  

    show dbs

    输入show dbs,显示当前所有数据库,这里显示了默认的数据库,如下图所示:

  4.  

    use 数据库名

    这个命令可以切换到指定的数据库,如果切换到了不存在的数据库,当在这个数据库存储数据时,就会自动创建这个数据库。

    我们输入show school,切换到school数据库,这里返回了switched to db school,如下图所示:

  5.  

    show collections

    这个命令可以显示当前数据库下的所有集合,我们输入show collections试一下,可以发现,students数据库下什么集合都没有,如下图所示:

  6.  

    db.collection.insert()

    这个方法把文档插入到集合中,我们输入db.student.insert({name:"hushiyun",age:24}),将一条数据(文档)插入。这里返回的结果显示已经插入了一条文档,如下图所示:

  7.  

    db.collection.find()

    这个方法可以查询当前集合中所有的文档,我们输入进去查询一下,这样就查到了我们刚才插入的那一条文档,如下图所示:

图解Mongo Shell的使用的更多相关文章

  1. MongoDB error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js(转)

    rror: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js 一般这种情况就是:自己指定的数据库,所以不能.自动加 ...

  2. 常见的mongo shell命令

    启动mongo shell 在windows下,双击mongo.exe可以启动mongo shell 查询库.表及选择库 查询所有库命令: show dbs 应用某一个db use jxs_datab ...

  3. MongoDB - The mongo Shell, mongo Shell Quick Reference

    mongo Shell Command History You can retrieve previous commands issued in the mongo shell with the up ...

  4. MongoDB - The mongo Shell, Data Types in the mongo Shell

    MongoDB BSON provides support for additional data types than JSON. Drivers provide native support fo ...

  5. MongoDB - The mongo Shell, Write Scripts for the mongo Shell

    You can write scripts for the mongo shell in JavaScript that manipulate data in MongoDB or perform a ...

  6. MongoDB - The mongo Shell, Access the mongo Shell Help

    In addition to the documentation in the MongoDB Manual, the mongo shell provides some additional inf ...

  7. MongoDB - The mongo Shell, Configure the mongo Shell

    Customize the Prompt You may modify the content of the prompt by setting the variable prompt in the  ...

  8. MongoDB - Introduction of the mongo Shell

    Introduction The mongo shell is an interactive JavaScript interface to MongoDB. You can use the mong ...

  9. couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145

    当直接执行./mongo 出现这样的提示:couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 解决: ...

随机推荐

  1. 模板汇总——LCT

    link-cut tree #define lch(x) tr[x].son[0] #define rch(x) tr[x].son[1] ; struct Node{ int rev, rt; ], ...

  2. 题解 yzoj1663: 愤怒的牛(二分) yzoj1662: 曲线(三分)

    话说二分和三分的题还没有整理过,就趁这两题来整理下笔记 先讲讲关于二分,对于二分的具体边界长期以来对我来说都是个玄学问题,都是边调边拍改对的.思路大体是确定左边界l,和有边界r,判断满足条件缩小范围. ...

  3. 程序员过关斩将--更加优雅的Token认证方式JWT

    菜菜,上次你讲的cookie和session认证方式,我这次面试果然遇到了 结果怎么样? 结果面试官问我还有没有更好的方式? 看来你又挂了 别说了,伤心呀.到底还有没有更好的方式呢? 你猜? 基于To ...

  4. 并发Bug之源有三,请睁大眼睛看清它们

    写在前面 生活中你一定听说过--能者多劳 作为 Java 程序员,你一定听过--这个功能请求慢,能加一层缓存或优化一下 SQL 吗? 看过中国古代神话故事的也一定听过--天上一天,地上一年 一切设计来 ...

  5. Java连载29-方法执行内存分析、方法重载

    一.JVM包含三个内存区:栈内存.堆内存.方法区内存 二.注意点 (1)在MyEclipse中字体是红色的是一个类的名字,并且这个类除了我们自定义的类是JavaSE类库中自带的 (2)其实JavaSE ...

  6. WoSign新证书系统通过德国Cure53安全测试

    近日,沃通WoSign新证书系统顺利通过德国Cure53白盒子安全测试,并公开发布审计报告总结版. 据悉,根据去年10月份Mozilla提出的整改要求,沃通WoSign投入研发力量高标准严要求地重新开 ...

  7. Vue之render渲染函数和JSX的应用

    一.模板缺陷 模板的最大特点是扩展难度大,不易扩展.可能会造成逻辑冗余 <Level :type="1">哈哈</Level> <Level :typ ...

  8. (六十五)c#Winform自定义控件-图标字体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  9. spring cloud config使用mysql存储配置文件

    spring cloud config使用mysql存储配置文件 1.结构图 2.pom.xml: <?xml version="1.0" encoding="UT ...

  10. Jenkins教程(五)构建Java服务Docker镜像

    本文主旨 主要记录下如何使用Jenkins构建Java服务的Docker镜像,以及手动部署测试下 前期准备 已安装Jenkins 为jenkins用户添加到docker组内 本地装有maven,配置或 ...