2020年7月1日 星期三

Mongo DB 使用語法


  • 查詢並轉存到另一 collection 

(等同SQL  insert into table_02 select * from table_01)

> var docs=db.table_01.find();
> docs.forEach(function(row){db.table_02.insert(row)});


  • Index操作

新增index
> db.docs.ensureIndex({"data.field1":1})

取得目前設定的index
> db.docs.getIndexs()

刪除index (參數帶getIndexs查到的name)
> db.docs.dropIndex("data.field1_1")


  • CENTOS重啟mongo db
systemctl stop mongod
systemctl start mongod

沒有留言:

張貼留言