国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MongoDB > 正文

MongoDB常用命令小結

2020-03-14 13:27:12
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了MongoDB的一些常用命令,學習與使用MongoDB數據庫的朋友可以參考下
 
 
MongoDB常用命令: 

超級用戶相關: 

use admin 
#增加或修改用戶密碼 
db.addUser(ixigua,'pwd') 
#查看用戶列表 
db.system.users.find() 
#用戶認證 
db.auth(ixigua,'pwd') 
#刪除用戶 
db.removeUser('mongodb') 
#查看所有用戶 
show users 
#查看所有數據庫 
show dbs 
#查看所有的collection 
show collections 
#查看各collection的狀態 
db.printCollectionStats() 
#查看主從復制狀態 
db.printReplicationInfo() 
#修復數據庫 
db.repairDatabase() 
#設置記錄profiling,0=off 1=slow 2=all 
db.setProfilingLevel(1) 
#查看profiling 
show profile 
#拷貝數據庫 
db.copyDatabase('mail_addr','mail_addr_tmp') 
#刪除collection 
db.mail_addr.drop() 
#刪除當前的數據庫 
db.dropDatabase() 


客戶端連接: 
/usr/local/mongodb/bin/mongo 8.8.88/ixigualib -u ixigua -p 'pwd' 


增刪改: 
#存儲嵌套的對象 
db.foo.save({'name':'ysz','address':{'city':'beijing','post':100096},'phone':[138,139]}) 
#存儲數組對象 
db.user_addr.save({'Uid':'yushunzhi@sohu.com','Al':['test-1@sohu.com','test-2@sohu.com']}) 
#根據query條件修改,如果不存在則插入,允許修改多條記錄 
db.foo.update({'yy':5},{'$set':{'xx':2}},upsert=true,multi=true) 
#刪除yy=5的記錄 
db.foo.remove({'yy':5}) 
#刪除所有的記錄 
db.foo.remove() 


索引: 
#增加索引:1(ascending),-1(descending) 
db.things.ensureIndex({firstname: 1, lastname: 1}, {unique: true}); 
#索引子對象 
db.user_addr.ensureIndex({'Al.Em': 1}) 
#查看索引信息 
db.deliver_status.getIndexes() 
db.deliver_status.getIndexKeys() 
#根據索引名刪除索引 
db.user_addr.dropIndex('Al.Em_1') 


查詢: 
#查找所有 
db.foo.find() 
#查找一條記錄 
db.foo.findOne() 
#根據條件檢索10條記錄 
db.foo.find({'msg':'Hello 1'}).limit(10) 
#sort排序 
db.deliver_status.find({'From':'ixigua@sina.com'}).sort({'Dt',-1}) 
db.deliver_status.find().sort({'Ct':-1}).limit(1) 
#count操作 
db.user_addr.count() 
#distinct操作 
db.foo.distinct('msg') 
#>操作 
db.foo.find({"timestamp": {"$gte" : 2}}) 
#子對象的查找 
db.foo.find({'address.city':'beijing'}) 


管理: 
#查看collection數據的大小 
db.deliver_status.dataSize() 
#查看colleciont狀態 
db.deliver_status.stats() 
#查詢所有索引的大小 
db.deliver_status.totalIndexSize() 
#查看當前所使用的數據庫 
db 

作者 mahout
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宁阳县| 元氏县| 扶绥县| 黄冈市| 鹤山市| 海宁市| 山东省| 青阳县| 扎囊县| 牙克石市| 白朗县| 汪清县| 高淳县| 渑池县| 达尔| 福安市| 桦甸市| 阿克苏市| 永昌县| 灌阳县| 兰溪市| 麻栗坡县| 郓城县| 沁水县| 石嘴山市| 新余市| 乌拉特中旗| 郎溪县| 呼伦贝尔市| 安岳县| 夹江县| 桐梓县| 宁乡县| 都匀市| 崇明县| 江门市| 海口市| 剑川县| 威信县| 赣榆县| 永泰县|