mongoDB4.0數(shù)據(jù)庫(kù)
下載:https://www.mongodb.com/
安裝:略
注意:使用前修改bin目錄下配置文件mongodb.cfg,刪除最后一行的'mp'字段
1. 啟動(dòng)服務(wù)與終止服務(wù)
net start mongodb
net stop mongodb
2.創(chuàng)建管理員用戶
mongo
use admin
db.createUser({user:"yxp",pwd:"997997",roles:["root"]})
3.使用賬戶密碼連接mongodb
mongo -u adminUserName -p userPassword --authenticationDatabase admin
4.數(shù)據(jù)庫(kù)
查看數(shù)據(jù)庫(kù)
show dbs
切換數(shù)據(jù)庫(kù)
use db_name
增加數(shù)據(jù)庫(kù)
db.table1.insert({'a':1}) 創(chuàng)建數(shù)據(jù)庫(kù)(切換到數(shù)據(jù)庫(kù)插入表及數(shù)據(jù))
刪除數(shù)據(jù)庫(kù)
db.dropDatabase() 刪數(shù)據(jù)庫(kù)(刪前要切換)
5.表
使用前先切換數(shù)據(jù)庫(kù)
查看表
show tables 查所有的表
增加表
use 庫(kù)
db.table1.insert({'b':2}) 增加表(表不存在就創(chuàng)建)
刪除表
db.table1.drop() 刪表
6.數(shù)據(jù)
增加數(shù)據(jù)
db.test.insert({‘name':'mac'}) 插入一條
db.user.insertMany([{},user2,user3,user4,user5]) 插入多條
刪除數(shù)據(jù)
db.user.deleteOne({ 'age': 8 }) 刪第一個(gè)匹配
db.user.deleteMany( {'addr.country': 'China'} ) 刪全部匹配
db.user.deleteMany({}) 刪所有
查看數(shù)據(jù)
db.user.find({'name':'alex'}) 查 相當(dāng)于where xx==xx
db.user.find({'name':{"$ne":'alex'}}) 查xx!=xx
db.user.find({'_id':{'$gt':2}}) 查xx>xx
db.user.find({"_id":{"$gte":2,}}) 查xx>=xx
db.user.find({'_id':{'$lt':3}}) 查xxxx
db.user.find({"_id":{"$lte":2}}) 查xx=xx
改數(shù)據(jù)
db.user.update({'_id':2},{"$set":{"name":"WXX",}}) 改數(shù)據(jù)
7.pymongo
client = pymongo.MongoClient(host=host,port=port, username=username, password=password)
db = client["db_name"] 切換數(shù)據(jù)庫(kù)
table = db['表名']
table.insert({}) 插入數(shù)據(jù)
table.remove({}) 刪除數(shù)據(jù)
table.update({'_id':2},{"$set":{"name":"WXX",}}) 改數(shù)據(jù)
table.find({}) 查數(shù)據(jù)
總結(jié)
以上所述是小編給大家介紹的mongoDB4.0數(shù)據(jù)庫(kù)的操作方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
您可能感興趣的文章:- 詳解MongoDB數(shù)據(jù)庫(kù)基礎(chǔ)操作及實(shí)例
- 老生常談MongoDB數(shù)據(jù)庫(kù)基礎(chǔ)操作
- mongodb數(shù)據(jù)庫(kù)基礎(chǔ)知識(shí)之連表查詢
- MongoDB數(shù)據(jù)庫(kù)插入、更新和刪除操作詳解
- PHP中MongoDB數(shù)據(jù)庫(kù)的連接、添加、修改、查詢、刪除等操作實(shí)例
- mongodb 數(shù)據(jù)庫(kù)操作詳解--創(chuàng)建,切換,刪除
- mongodb 數(shù)據(jù)庫(kù)操作--備份 還原 導(dǎo)出 導(dǎo)入
- MongoDB數(shù)據(jù)庫(kù)文檔操作方法(必看篇)
- MongoDB模糊查詢操作案例詳解(類關(guān)系型數(shù)據(jù)庫(kù)的 like 和 not like)
- mongodb數(shù)據(jù)庫(kù)入門學(xué)習(xí)筆記之下載、安裝、啟動(dòng)、連接操作解析
- MongoDB數(shù)據(jù)庫(kù)安裝配置、基本操作實(shí)例詳解
- MongoDB數(shù)據(jù)庫(kù)基礎(chǔ)操作總結(jié)