1. 程式人生 > >mongodb安裝過程與常用命令

mongodb安裝過程與常用命令

參考部落格:http://my.oschina.net/Kenyon/blog/99742


mongodb安裝過程

1、解壓縮

[[email protected] opt]# tar -zxvf mongodb-linux-i686-2.4.9.tgz

mongodb-linux-i686-2.4.9/README

mongodb-linux-i686-2.4.9/THIRD-PARTY-NOTICES

mongodb-linux-i686-2.4.9/GNU-AGPL-3.0

2、重新命名資料夾

[[email protected] opt]# mv mongodb-linux-i686-2.4.9 mongodb

3、建立資料庫日誌資料夾和資料資料夾

[

[email protected] mongodb]# mkdir log

[[email protected] mongodb]# mkdir data

4、啟動服務

[[email protected] mongodb]# cd bin

[[email protected] bin]#

[[email protected] bin]# ./mongod --dbpath=/opt/mongodb/data --logpath=/opt/mongodb/log/mongodb.log --logappend &

[1] 16334

[[email protected]
bin]# all output going to: /opt/mongodb/log/mongodb.log

5、注意安裝的版本(32位還是64位)否則啟動服務可能報下面的錯誤

[[email protected] bin]# ./mongod: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

mongodb常用命令

1、連線mongodb

[[email protected] opt]# cd mongodb/bin

[
[email protected]
bin]# ./mongo

MongoDB shell version: 2.4.9

connecting to: test

> use local

switched to db local

> show collections

ewalletlog

ewalletlogs

startup_log

system.indexes

>

> db.ewalletlogs.find();

2、檢視現有的資料庫> show dbs;
local   (empty)
test    0.203125GB

3、資料庫切換> use local;
switched to db local
> use test;
switched to db test
>

4、顯示collctions> show collections;
kenyon
system.indexes
test
things
>

5、資料插入方式一(save):
> db.kenyon.save({id:8899,name:'kenyon_test_mongo'});
> db.kenyon.save({id:99,name:'kenyon_test_mongo',remark:'first time here'});

方式二(預定義):
> tmp={id:0909,name:'kenyon_test',create_time:'2013-01-01'};
> db.kenyon.insert(tmp);

方式三(迴圈插):
> for (var i = 1; i <= 25; i++) db.tab_kenyon.insert( { x : 4 , j : i } )
> db.tab_kenyon.find();
{ "_id" : ObjectId("50e4b8007a86419166fd68f0"), "x" : 4, "j" : 1 }
{ "_id" : ObjectId("50e4b8007a86419166fd68f1"), "x" : 4, "j" : 2 }
{ "_id" : ObjectId("50e4b8007a86419166fd68f2"), "x" : 4, "j" : 3 }


如果不存在collection會自動建立,不會報錯,顯示資料時預設是顯示20條資料,輸入it來檢視下一頁的20條資料

6、資料檢索

1) 普通方式> db.kenyon.find();
{ "_id" : ObjectId("50e49c55f8de48037fe44062"), "name" : "mongo" }
{ "_id" : ObjectId("50e49d2ecd320366f7122605"), "name" : "mongo", "id" : "888" }
{ "_id" : ObjectId("50e4b3fe7a86419166fd68ed"), "id" : 8899, "name" : "kenyon_test_mongo" }
{ "_id" : ObjectId("50e4b4167a86419166fd68ee"), "id" : 99, "name" : "kenyon_test_mongo", "remark" : "first time here" }
{ "_id" : ObjectId("50e4b6817a86419166fd68ef"), "id" : 909, "name" : "kenyon_test", "create_time" : "2013-01-01" }

2)查詢一條資料> db.kenyon.findOne();
{ "_id" : ObjectId("50e49c55f8de48037fe44062"), "name" : "mongo" }

3)條件檢索> db.kenyon.find();
{ "_id" : ObjectId("50e49c55f8de48037fe44062"), "name" : "mongo" }
{ "_id" : ObjectId("50e49d2ecd320366f7122605"), "name" : "mongo", "id" : "888" }
{ "_id" : ObjectId("50e4b3fe7a86419166fd68ed"), "id" : 8899, "name" : "kenyon_test_mongo" }
{ "_id" : ObjectId("50e4b4167a86419166fd68ee"), "id" : 99, "name" : "kenyon_test_mongo", "remark" : "first time here" }
{ "_id" : ObjectId("50e4b6817a86419166fd68ef"), "id" : 909, "name" : "kenyon_test", "create_time" : "2013-01-01" }

> db.kenyon.find({id:909});
{ "_id" : ObjectId("50e4b6817a86419166fd68ef"), "id" : 909, "name" : "kenyon_test", "create_time" : "2013-01-01" }

> db.kenyon.find({name:"mongo"});
{ "_id" : ObjectId("50e49c55f8de48037fe44062"), "name" : "mongo" }
{ "_id" : ObjectId("50e49d2ecd320366f7122605"), "name" : "mongo", "id" : "888" }

4) 通過正則表示式進行模糊查詢

>db.ewalletlogs.find({message:/^2014-02-13 12:*/});

5)限制查詢(limit)

> db.kenyon.find().limit(2)
{ "_id" : ObjectId("50e49c55f8de48037fe44062"), "name" : "mongo" }
{ "_id" : ObjectId("50e49d2ecd320366f7122605"), "name" : "mongo", "id" : "888" }


7、mongo的shell幫助> help
        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                 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


>


相關推薦

mongodb安裝過程常用命令

參考部落格:http://my.oschina.net/Kenyon/blog/99742mongodb安裝過程 1、解壓縮 [[email protected] opt]# tar -zxvf mongodb-linux-i686-2.4.9.tgz mongo

MongoDB 安裝詳細教程 + 常用命令 + Python 的互動

MongoDB 簡介 MongoDB (名稱來自 humongous/巨大無比的, 是一個可擴充套件的高效能,開源,模式自由,面向文件的NoSQL,基於 分散式 檔案儲存,由 C++ 語言編寫,設計之初旨在為 WEB 應用提供可擴充套件的高效能資料儲存解決方案。 MongoDB使用的是記憶體對映儲存引

docker虛擬化安裝配置常用命令

sta 80端口 ubuntu map 虛擬化 導出 6.5 關系 版本 一、Docker安裝配置 docker只有在centos6.5以上機器才能使用yum直接安裝,如果其他版本需要安裝centos擴展源epel。 docker官方文檔說要求Linux kernel至

MongoDB基礎知識常用命令

SQL術語/概念 MongoDB術語/概念 解釋/說明 database database 資料庫 table collection 資料庫表/集合 row docu

Mongodb 安裝過程服務無法啟動100、48問題

安裝過程: 1.在解壓後的mongodb的資料夾裡建立 data檔案(再往裡新增db檔案)和logs檔案(新建mongodb.log); eg: D:\MongoDB\data\db D:\MongoDB\logs\mongodb.log 2.

Fedora 安裝常用命令

org 地址 安裝 tps 下載 stage2 gpo 編輯 6.2 fedora下載地址: https://getfedora.org/ 原來裝的26,現在裝27 用的是server版網絡安裝500多M 現在都是U盤安裝了,fedora的寫優盤說明 https://f

Anaconda 的安裝常用命令

x86 channels logs channel 安裝包 管理命令 tap ive onf Anaconda 自帶 Python 解釋器以及數據處理常用的第三方庫,可以非常方便地搭建 Python 環境。同時還自帶了 Conda 用來管理第三方庫,類似 Pip ,但是比

mongoDB安裝,配置及常用命令

技術 中新 ima jpg 圖片 命令 cmd b數 nbsp 1.安裝及配置 第一步 安裝 custom 用來修改安裝目錄 進入安裝目錄的bin文件,輸入cmd 再輸入mongo 如果出現下圖則表示安裝成功 D:\applay\mongoDB\bin是我的安裝目錄

docker compose安裝常用命令介紹 及使用docker-compose執行一個進銷存管理系統

使用微服務架構的應用系統一般包含若干個微服務,每個微服務一般都會部署多個例項。如果每個微服務都要手動啟停,那麼效率之低,維護量之大可想而知 docker compose 是一個用於定義和執行多容器docker應用程式的工具   安裝: 下在並安裝適應系統版本的compose

windows 下 RabbitMQ 安裝常用命令

轉載自https://www.cnblogs.com/ericli-ericli/p/5902270.html 最近學習 rabbitMQ 的配置,這裡只是做一個記錄。 注意 rabbitMQ 的版本  和  erlang 的版本的相容性。詳情見 https:/

linux安裝常用命令

一 從認識作業系統開始 1.1 作業系統簡介 我通過以下四點介紹什麼是作業系統: 作業系統(Operation System,簡稱OS)是管理計算機硬體與軟體資源的程式,是計算機系統的核心與基石; 作業系統本質上是執行在計算機上的軟體程式 ; 為使用者提供一個與系統互動

docker 阿里雲安裝常用命令

  安裝沒得技術含量,看過菜鳥教程和純潔寫的部落格,感覺so easy 命令:  yum install docker 啟動 設定開機啟動 systemctl start docker.service systemctl enable docker.service &nb

git編譯安裝常用命令

git編譯安裝與常用命令 ========================================= 一:編譯安裝與設定 1.1:簡介 github官網地址(下載原始碼包):https://github.com/git/git.git git 在 windows mac

關於安裝MongoDB過程錯誤48 100的解決方法

   最近開始學習MongoDB,在安裝的時候遇到了很多問題,所以在此與大家分享一下我的MongoDB安裝方法總結   1.   下載mongoDB與安裝。         我的MongoDB資料夾在D:\mongodb        配置系統環境變數,在系統的path裡新增

快速掌握mongoDB(一)——mongoDB安裝部署和常用shell命令

1.mongoDB簡介   mongoDB 是由C++語言編寫的,是一種分散式的面向文件儲存的開源nosql資料庫。nosql是Not Only SQL的縮寫,是對不同於傳統的關係型資料庫的資料庫管理系統的統稱。   mongoDB是無模式的文件資料庫,在關係型資料庫中,資料表的每一行都擁有一樣的欄位,欄

lvm基本知識常用命令

pv vg lv linux lvm lvm基礎知識: lvm是Logical Volume Manager(邏輯卷管理)的縮寫,可以理解為一種硬盤分區管理工具,有以下幾個重要的基礎術語:物理卷(Pyhsical Volume,PV):是由系統的基礎存儲設備,如/dev/sda,/d

Centos7 安裝docker 以及常用命令

span 都是 docker upd 安裝 image mysq x86_64 查看系統 Centos7 安裝docker 以及常用命令 1.查看系統版本: $uname -r 3.10.0-693.el7.x86_64 ----------------------

自動化運維之ansible-安裝部署基礎命令

ip地址 cksum keygen python 了解 success 系統 ron pytho 一、Ansible簡介 Ansible基於Python語言開發,集合了眾多優秀運維工具的優點,實現了批量運行命令、部署程序、配置系統等功能。 二、安裝部署Ansible服務 A

MongoDB 查詢語法常用查詢語句總結

MongoDB 常用查詢語句總結 先來一波查詢語句語法的基本解釋: 列子: db.mycol.find({"likes": {$gt:10}, $or: [{"by": "yiibai tutorials"}, {"title": "MongoDB Overview"}]}

Zookeeper 安裝部署及常用命令

服務管理 啟動ZK服務: zkServer.sh start 檢視ZK狀態: zkServer.sh status 停止ZK服務: zkServer.sh stop 重啟ZK服務: zkServer.sh restart 終端操作 使用 zkCli 可以簡單的對 Zo