Mongodb常用操作

來源:互聯網
上載者:User

標籤:允許   檔案   roo   section   family   相同   use   font   json   

  mongodb也是一個資料庫,和mysql一樣,有伺服器、資料庫、表、記錄概念。同樣可以在終端中使用命令操作。

1、串連mongodb

mongo 127.0.0.1:27017

2、顯示所有資料庫

show dbs;

3、使用資料庫

use test;

4、查看資料庫下集合(表)

show collections;

5、操作某個集合

db.person.find();

6、查看當前操作的資料庫

db.getName();

 

Mongodb執行javascript

       Mongodb支援運行JavaScript,和一般的JavaScript基本相同。

允許一般有以下幾種方式:
1、在mongodb串連用戶端直接運行。例如在Robo 3T中編輯並運行JS

2、mongo --eval 運行一段指令碼

不進入互動模式,直接在 OS 的命令列下運行一段mongodb指令碼。

mongo127.0.0.1:27017/test --eval "printjson(db.users.findOne())"

3、在OS命令列下,運行一個js檔案

mongo 127.0.0.1:27017/testuserfindone.js

userfindone.js 的內容:

printjson(db.users.findOne());

4、在mongo shell 互動模式下,運行一個js檔案

mongo test

load("/root/mongojs/userfindone.js")

Mongodb常用操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.