mongodb資料庫常用操作命令

2021-09-03 02:44:32 字數 1180 閱讀 1757

資料庫開機(開機後這個控制台就放一邊不要動了,–dbpath 為自己建的資料夾路徑)

mongod --dbpath e:\mongodb_data

連線資料庫(另起乙個控制台,在這裡進行資料庫操作)

mongo

建立資料庫(用哪個資料庫,我的資料庫叫test)

use test

插入資料(沒有student集合會自己建立乙個)

db.student.insert();

匯入外部json檔案

momgoimport --db test --collection student --drop --file primer-dataset.json

–db test 想往哪個資料庫裡面匯入

–collection student 想往哪個集合中匯入

–drop 把集合清空

–file primer-dataset.json file後面是檔案路徑,如c:\users\1.json

刪除資料庫

db.dropdatabase();

刪除集合

db.student.drop();

刪除資料:

db.student.remove(});

刪除一次資料:

db.student.remove(,);

列出所有資料庫

show dbs

檢視當前在哪個資料庫裡

db檢視集合

show collections

檢視集合中的所有資料

db.student.find();

檢視集合中的有多少條資料

db.student.find().count();

查詢一條資料

db.student.find();

多個條件

db.student.find();

大於條件

db.student.find(});

或邏輯查詢

db.student.find(,]});

更新一條資料

db.student.update(,});

更新多條資料

db.student.update(,},);

完整更新一條資料

db.student.update(,);

查詢結果排序:

db.student.find().sort();

Mongodb資料庫常用

mongodb的預設資料庫為 db 該資料庫儲存在data目錄中 show dbs 顯示所有資料庫列表 db 顯示當前資料庫物件或者集合 use dbname 連線乙個指定的資料庫 文件即行row,是一組的鍵值對 bson mongod 是資料庫的服務端 mongo是資料庫的客戶端 連線資料庫 首先...

MongoDB 資料庫操作

1 插入記錄 使用資料庫 如果沒有該資料庫就會建立,有就進入該模式 use use my testdb 插入資料 db.user.insert db.user.insert 顯示資料庫 show dbs my mongodb是隱式建立的資料庫 顯示表 show collections user是隱式...

mongodb資料庫常用的操作指令

啟動資料庫 net start mongodb 關閉資料庫 net stop mongodb 庫操作 mongo 進入命令模式 use dbname 建立乙個新庫 show dbs 檢視所有庫 db.dropdatabase 刪除資料庫 exit 退出命令模式 集合操作 db.createcolle...