本博文介绍了MongoDB,并详细指引读者在Ubuntu下MongoDB的安装和使用。本教程在Ubuntu14.04下测试通过.(2017.09.07)

安装MongoDB

MongoDB安装很简单,无需下载源文件,可以直接用apt-get命令进行安装。
打开终端,输入以下命令:

sudo apt-get install mongodb

安装完成后,在终端输入以下命令查看MongoDB版本:
mongo -version

输出版本信息,表明安装成功,如下:

root@ubantu:/usr/src# mongo -version
MongoDB shell version: 2.4.9 启动和关闭mongodb命令如下:
service mongodb start
输入命令,结果如下:
root@ubantu:/usr/src# service mongodb start
start: Job is already running: mongodb service mongodb stop
默认设置MongoDB是随Ubuntu启动自动启动的。
输入以下命令查看是否启动成功:
pgrep mongo -l   #注意:-l是英文字母l,不是阿拉伯数字1

卸载MongoDB
sudo apt-get --purge remove mongodb mongodb-clients mongodb-server

使用MongoDB

shell命令模式

输入mongo进入shell命令模式,默认连接的数据库是test数据库,在此之前一定要确保你已经启动了MongoDB,否则会出现错误,启动之后运行成功,如下图:

root@ubantu:/usr/src# mongo
MongoDB shell version: 2.4.9
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
>
常用操作命令:

db.help()                    help on db methods
    db.mycoll.help()             help on collection methods
    sh.help()                    sharding helpers
    rs.help()                    replica set helpers
    help admin                   administrative help
    help connect                 connecting to a db help
    help keys                    key shortcuts
    help misc                    misc things to know
    help mr                      mapreduce

show dbs                     show database names
    show collections             show collections in current database
    show users                   show users in current database
    show profile                 show most recent system.profile entries with time >= 1ms
    show logs                    show the accessible logger names
    show log [name]              prints out the last segment of log in memory, 'global' is default
    use <db_name>                set current database
    db.foo.find()                list objects in collection foo
    db.foo.find( { a : 1 } )     list objects in foo where a == 1
    it                           result of the last line evaluated; use to further iterate
    DBQuery.shellBatchSize = x   set default number of items to display on shell
    exit                         quit the mongo shell

Ubuntu下MongoDB的安装和使用的更多相关文章

  1. Ubuntu下MongoDB的安装

    一.MongoDB介绍 MongoDB 是一个是一个基于分布式文件存储的数据库,介于关系数据库和非关系数据库之间,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似jso ...

  2. [转] ubuntu 下mongodb的安装-----这篇文章也不错

    在Ubuntu下进行MongoDB安装步骤 一. 在Ubuntu下最傻瓜的步骤(以下都在root用户下进行操作): 1.运行"apt-get install mongo" 如果遇到 ...

  3. 1. Ubuntu下MongoDB的安装和使用

    一.MongoDB介绍 MongoDB 是一个是一个基于分布式文件存储的数据库,介于关系数据库和非关系数据库之间,是非关系数据库当中功能最丰富,最像关系数据库的.他支持的数据结构非常松散,是类似jso ...

  4. Ubuntu下git的安装与使用

    Ubuntu下git的安装与使用 Ubuntu下git的安装与使用与Windows下的大致相同,只不过个人感觉在Ubuntu下使用git更方便. 首先,确认你的系统是否已安装git,可以通过git指令 ...

  5. Linux下MongoDB服务安装

    Linux下MongoDB服务安装 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案.MongoDB是一个介于关系数据库和非关系数据 ...

  6. Ubuntu下Speedtest的安装

    要安装Speedtest,需要先安装apache,参见<Ubuntu下Apache的安装>一文:*(再安装LAMP server,参见<Ubuntu下快速安装LAMP server& ...

  7. Ubuntu下Apache的安装

    Ubuntu下可快速安装LAMP server(Apache+MySQL+PHP5),参见<Ubuntu下快速安装LAMP server>一文. 也可以手动安装Apache.本文介绍如何手 ...

  8. Linux(Ubuntu)下MySQL的安装与配置

    转自:http://www.2cto.com/database/201401/273423.html 在Linux下MySQL的安装,我一直觉得挺麻烦的,因为之前安装时就是由于复杂的配置导致有点晕.今 ...

  9. ubuntu下的openfire安装、配置、运行

    openfire服务器              Openfire 采用Java开发,开源的实时协作(RTC)服务器基于XMPP(Jabber)协议.您可以使用它轻易的构建高效率的即时通信服务器.Op ...

随机推荐

  1. Vue组件进阶知识总结

    上一篇我们重点介绍了组件的创建.注册和使用,熟练这几个步骤将有助于深入组件的开发.另外,在子组件中定义props,可以让父组件的数据传递下来,这就好比子组件告诉父组件:“嘿,老哥,我开通了一个驿站,你 ...

  2. Linux 内核参数 和 Oracle相关参数调整

    Linux 内核参数 和 Oracle相关参数调整 分类: Oracle Basic Knowledge2009-10-14 12:23 9648人阅读 评论(0) 收藏 举报 oraclelinux ...

  3. cmdb是什么

    CMDB -- Configuration Management Database 配置管理数据库,CMDB存储与管理企业IT架构中设备的各种配置信息,它与所有服务支持和服务交付流程都紧密相联,支持这 ...

  4. HTML5 Canvas 笛卡尔坐标系转换尝试

    <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type&quo ...

  5. docker集群——初识Swarm

    为Docker构建原生的集群管理工具的计划早在2014年初就开始了,当时作为一个通信协议项目,称为Beam.之后,它被实现为一种后台程序,使用Docker API来控制异构化的分布式系统.项目重新命名 ...

  6. node - 导包机制

    在学node js的时候,经常各种导包 let http = require('http'); 然后它的运行机制: 1. 查找当前目录下面的node_modules 2. 全局查找(首先添加到path ...

  7. Visual studio C++ MFC之树形控件Tree Control

    背景 本篇旨在MSDN帮助文档下总结树形控件Tree Control的使用,并列出碰到的具体问题. 正文 树形控件Tree Control的类则是CTreeCtrl,具体成员对象详见链接,以下则描述一 ...

  8. Keep-Alive简介及在Tomcat中配置

      Keep-Alive功能使客户端到服务器端的连接持续有效,当出现对服务器的后继请求时,Keep-Alive功能避免了建立或者重新建立连接.市场上 的大部分Web服务器,包括iPlanet.IIS和 ...

  9. jpa in查询

    List<Integer> ids = new ArrayList<Integer>(); ids.add(1); ids.add(2); Map<String, Obj ...

  10. velcoity使用说明:foreach指令

    http://blog.csdn.net/madding/article/details/6641020当在velocity中需要显示一个列表信息,我们会用foreach循环输出, 要求: 假如现在需 ...