Mongodb installation & userguide

本文详细介绍了MongoDB在Ubuntu系统的安装步骤,包括下载、解压、目录配置及运行等,并提供了基本的使用操作指南,如数据库和集合的创建、查询及增删改等常用命令。

 

1.Mongodb Installation in Ubuntu

 

(1) Download from: https://www.mongodb.org/downloads

     File: mongodb-linux-x86_64-ubuntu1404-3.0.6.tgz

(2) Decompressing files.

  tar zxf mongodb-linux-x86_64-ubuntu1404-3.0.6.tgz

  mv mongodb-linux-x86_64-ubuntu1404-3.0.6 /usr/local/mongodb

(3) Create default directories for mongdb data files.

mkdir data

cd data

mkdir db

(4) Create default logs file.

  touch logs

(5) Run mongod.

--fork                      fork server process

--dbpath arg     directory for datafiles - defaults to /data/db

  --logpath arg     log file to send write to instead of stdout - has to be a file, not directory

  --httpinterface          enable http interface

  cd bin

  ./mongod --dbpath=/usr/local/mongodb/mongodb/data/db --fork --httpinterface --logpath=/usr/local/mongodb/mongodb/logs

(6) Check mongod process.

  ps -ef | grep mongo

(7) Check mongodb information.

  http://192.168.98.70:28017/

(8) Enter mongo shell.

  cd bin 

  ./mongo

MongoDB shell version: 3.0.6

connecting to: test

Welcome to the MongoDB shell.

For interactive help, type "help".

 

2.Use Mongodb.

 

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

 

3.CRUD.

 

  db.foo.insert({name:'edison',age:28})

  db.foo.insert({name:'scofield',age:30})

  db.foo.find()

  db.foo.find({name:'edison'})

  db.foo.update({name:'edison'},{name:'edison',age:40})

  db.foo.remove({age:40})

转载于:https://www.cnblogs.com/edisonxiang/p/4775750.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值