title: Ubuntu-MongoDB 配置
date: 2018-07-01 16:01:33
categories:

  • Linux
  • Linux
    tags: [linux,linux]

安装环境及版本:

  • 系统:ubuntu 18.04 LTS

  • MongoDB:

一 安装

  1. sudo apt update && sudo apt upgrade -y
  2. sudo apt install mongodb
  3. sudo systemctl status mongodb

默认端口: 27017

二 使用

  1. 基础命令
    1. #进入命令行
    2. mongo
    3. #显示所有数据库
    4. show dbs
    5. #切换数据库
    6. use admin
    7. #退出
    8. quit()
  1. 插入数据
    1. use admin
    2. db.restaurants.insert(
    3. {
    4. "borough" : "Manhattan",
    5. "cuisine" : "Italian",
    6. "name" : "Vella",
    7. "id" : "41704620"
    8. }
    9. )
  1. 查询
    db.col.find()
    
  1. 更新
    db.restaurants.update(
     { "name" : "Vella" },
     {
       $set: { "cuisine": "American (New)" },
       $currentDate: { "lastModified": true }
     }
    )
    
  1. 删除
    #删除一个集合中的所有文档,传递一个空的条件文档即可
    db.restaurants.remove( { } )
    #删除一个集合
    db.restaurants.drop()
    

三 卸载

sudo systemctl stop mongodb
sudo apt purge mongodb
sudo apt autoremove