MongoDB 術(shù)語(yǔ).概念
1.database 數(shù)據(jù)庫(kù)? 2.collection 數(shù)據(jù)庫(kù)表/集合
3.document 數(shù)據(jù)記錄行/文檔? 4.field? 數(shù)據(jù)字段/域
5.index 索引? 6.primary key 主鍵 自動(dòng)將_id字段設(shè)置為主鍵
MongoDB基本語(yǔ)法
db.createCollection("user")? 創(chuàng)建集合user
db.user.insert({userId:1,userName:'jack',userAge:28,class:{name:'164',num:10}})創(chuàng)建集合并插入數(shù)據(jù)
show collections? 查看集合
db.dropDatabase()? ?刪除數(shù)據(jù)庫(kù)
db.user.drop()? ?刪除user集合
db.user.findOne() 查看user集合中第一條數(shù)據(jù)
db.user.update({userName:'jack'.{$set:{userAge:30}})? 將userName是jack的userAge更新為30
db.user.update({userName:'jack'.{$set:{'class.name':'163'}})更新子集合
db.user.find({userName:'jack'})查看數(shù)據(jù)
db.user.find({'class.name':'163'})子集合條件查詢(xún)
db.user.find({userAge:{$gt:20}})查詢(xún)userAge大于20的
db.user.remove({userId:101})刪除userId為101的數(shù)據(jù)