婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > MongoDB 語(yǔ)法使用小結(jié)

MongoDB 語(yǔ)法使用小結(jié)

熱門(mén)標(biāo)簽:高德地圖標(biāo)注商戶位置 智能電銷機(jī)器人銷售話術(shù) 企業(yè)智能外呼系統(tǒng)價(jià)格多少 沈陽(yáng)營(yíng)銷電銷機(jī)器人招商 機(jī)器人外呼系統(tǒng)軟件存在問(wèn)題 兗州電話外呼營(yíng)銷系統(tǒng) 南京400電話怎樣辦理 徐州ai電銷機(jī)器人原理 福州電銷機(jī)器人源代碼
他支持的數(shù)據(jù)結(jié)構(gòu)非常松散,是類似json的bjson格式,因此可以存儲(chǔ)比較復(fù)雜的數(shù)據(jù)類型。Mongo最大的特點(diǎn)是他支持的查詢語(yǔ)言非常強(qiáng)大,其語(yǔ)法有點(diǎn)類似于面向?qū)ο蟮牟樵冋Z(yǔ)言,幾乎可以實(shí)現(xiàn)類似關(guān)系數(shù)據(jù)庫(kù)單表查詢的絕大部分功能,而且還支持對(duì)數(shù)據(jù)建立索引。
它的特點(diǎn)是高性能、易部署、易使用,存儲(chǔ)數(shù)據(jù)非常方便。

1. MongoDB的獲取和安裝

(1)獲取地址 http://www.mongodb.org/downloads 根據(jù)自己需要選擇相應(yīng)的版本,linux下可以使用wget 命令。
(2)解壓 mongodb-win32-i386-1.8.1
(3)創(chuàng)建數(shù)據(jù)存放文件夾,mongodb默認(rèn)的數(shù)據(jù)目錄 /data/db
C:/> mkdir /data
C:/> mkdir /data/db
(4)運(yùn)行 MongoDB
mongod.exe - 數(shù)據(jù)庫(kù)的服務(wù)器端,相當(dāng)于mysql的 mysqld命令,啟動(dòng)服務(wù)器端
mongo.exe - 數(shù)據(jù)庫(kù)的客戶端,相當(dāng)于mysql的mysql命令,打開(kāi)管理控制臺(tái)

啟動(dòng)服務(wù)
mongod.exe --dbpath F:/DataBase/MongoDB/db/
--dbpath 數(shù)據(jù)文件存放路徑
--port 數(shù)據(jù)服務(wù)端口
C:/> cd /my_mongo_dir/bin
C:/my_mongo_dir/bin > mongod //啟動(dòng)mongod 服務(wù)器,默認(rèn)的數(shù)據(jù)庫(kù)路徑 /data/db,端口27071
啟動(dòng)客戶端
mongo.exe cclove
cclove 所連接的數(shù)據(jù)庫(kù)名稱
C:/> cd /my_mongo_dir/bin
C:/my_mongo_dir/bin> mongo

2. 熟悉MongoDB的數(shù)據(jù)操作語(yǔ)句,類sql

數(shù)據(jù)庫(kù)操作語(yǔ)法
mongo --path
db.AddUser(username,password) 添加用戶
db.auth(usrename,password) 設(shè)置數(shù)據(jù)庫(kù)連接驗(yàn)證
db.cloneDataBase(fromhost) 從目標(biāo)服務(wù)器克隆一個(gè)數(shù)據(jù)庫(kù)
db.commandHelp(name) returns the help for the command
db.copyDatabase(fromdb,todb,fromhost) 復(fù)制數(shù)據(jù)庫(kù)fromdb---源數(shù)據(jù)庫(kù)名稱,todb---目標(biāo)數(shù)據(jù)庫(kù)名稱,fromhost---源數(shù)據(jù)庫(kù)服務(wù)器地址
db.createCollection(name,{size:3333,capped:333,max:88888}) 創(chuàng)建一個(gè)數(shù)據(jù)集,相當(dāng)于一個(gè)表
db.currentOp() 取消當(dāng)前庫(kù)的當(dāng)前操作
db.dropDataBase() 刪除當(dāng)前數(shù)據(jù)庫(kù)
db.eval(func,args) run code server-side
db.getCollection(cname) 取得一個(gè)數(shù)據(jù)集合,同用法:db['cname'] or db.cname
db.getCollenctionNames() 取得所有數(shù)據(jù)集合的名稱列表
db.getLastError() 返回最后一個(gè)錯(cuò)誤的提示消息
db.getLastErrorObj() 返回最后一個(gè)錯(cuò)誤的對(duì)象
db.getMongo() 取得當(dāng)前服務(wù)器的連接對(duì)象get the server connection object
db.getMondo().setSlaveOk() allow this connection to read from then nonmaster membr of a replica pair
db.getName() 返回當(dāng)操作數(shù)據(jù)庫(kù)的名稱
db.getPrevError() 返回上一個(gè)錯(cuò)誤對(duì)象
db.getProfilingLevel() ?什么等級(jí)
db.getReplicationInfo() ?什么信息
db.getSisterDB(name) get the db at the same server as this onew
db.killOp() 停止(殺死)在當(dāng)前庫(kù)的當(dāng)前操作
db.printCollectionStats() 返回當(dāng)前庫(kù)的數(shù)據(jù)集狀態(tài)
db.printReplicationInfo()
db.printSlaveReplicationInfo()
db.printShardingStatus() 返回當(dāng)前數(shù)據(jù)庫(kù)是否為共享數(shù)據(jù)庫(kù)
db.removeUser(username) 刪除用戶
db.repairDatabase() 修復(fù)當(dāng)前數(shù)據(jù)庫(kù)
db.resetError()
db.runCommand(cmdObj) run a database command. if cmdObj is a string, turns it into {cmdObj:1}
db.setProfilingLevel(level) 0=off,1=slow,2=all
db.shutdownServer() 關(guān)閉當(dāng)前服務(wù)程序
db.version() 返回當(dāng)前程序的版本信息

數(shù)據(jù)集(表)操作語(yǔ)法
db.linlin.find({id:10}) 返回linlin數(shù)據(jù)集ID=10的數(shù)據(jù)集
db.linlin.find({id:10}).count() 返回linlin數(shù)據(jù)集ID=10的數(shù)據(jù)總數(shù)
db.linlin.find({id:10}).limit(2) 返回linlin數(shù)據(jù)集ID=10的數(shù)據(jù)集從第二條開(kāi)始的數(shù)據(jù)集
db.linlin.find({id:10}).skip(8) 返回linlin數(shù)據(jù)集ID=10的數(shù)據(jù)集從0到第八條的數(shù)據(jù)集
db.linlin.find({id:10}).limit(2).skip(8) 返回linlin數(shù)據(jù)集ID=1=的數(shù)據(jù)集從第二條到第八條的數(shù)據(jù)
db.linlin.find({id:10}).sort() 返回linlin數(shù)據(jù)集ID=10的排序數(shù)據(jù)集
db.linlin.findOne([query]) 返回符合條件的一條數(shù)據(jù)
db.linlin.getDB() 返回此數(shù)據(jù)集所屬的數(shù)據(jù)庫(kù)名稱
db.linlin.getIndexes() 返回些數(shù)據(jù)集的索引信息
db.linlin.group({key:...,initial:...,reduce:...[,cond:...]})
db.linlin.mapReduce(mayFunction,reduceFunction,optional params>)
db.linlin.remove(query) 在數(shù)據(jù)集中刪除一條數(shù)據(jù)
db.linlin.renameCollection(newName) 重命名些數(shù)據(jù)集名稱
db.linlin.save(obj) 往數(shù)據(jù)集中插入一條數(shù)據(jù)
db.linlin.stats() 返回此數(shù)據(jù)集的狀態(tài)
db.linlin.storageSize() 返回此數(shù)據(jù)集的存儲(chǔ)大小
db.linlin.totalIndexSize() 返回此數(shù)據(jù)集的索引文件大小
db.linlin.totalSize() 返回些數(shù)據(jù)集的總大小
db.linlin.update(query,object[,upsert_bool]) 在此數(shù)據(jù)集中更新一條數(shù)據(jù)
db.linlin.validate() 驗(yàn)證此數(shù)據(jù)集
db.linlin.getShardVersion() 返回?cái)?shù)據(jù)集共享版本號(hào)

db.linlin.find({'name':'foobar'}) select * from linlin where name='foobar'
db.linlin.find() select * from linlin
db.linlin.find({'ID':10}).count() select count(*) from linlin where ID=10
db.linlin.find().skip(10).limit(20) 從查詢結(jié)果的第十條開(kāi)始讀20條數(shù)據(jù) select * from linlin limit 10,20 ----------mysql
db.linlin.find({'ID':{$in:[25,35,45]}}) select * from linlin where ID in (25,35,45)
db.linlin.find().sort({'ID':-1}) select * from linlin order by ID desc
db.linlin.distinct('name',{'ID':{$lt:20}}) select distinct(name) from linlin where ID20

db.linlin.group({key:{'name':true},cond:{'name':'foo'},reduce:function(obj,prev){prev.msum+=obj.marks;},initial:{msum:0}})
select name,sum(marks) from linlin group by name
db.linlin.find('this.ID20',{name:1}) select name from linlin where ID20

db.linlin.insert({'name':'foobar','age':25}) insert into linlin ('name','age') values('foobar',25)
db.linlin.insert({'name':'foobar','age':25,'email':'cclove2@163.com'})

db.linlin.remove({}) delete * from linlin
db.linlin.remove({'age':20}) delete linlin where age=20
db.linlin.remove({'age':{$lt:20}}) delete linlin where age20
db.linlin.remove({'age':{$lte:20}}) delete linlin where age=20
db.linlin.remove({'age':{$gt:20}}) delete linlin where age>20
db.linlin.remove({'age':{$gte:20}}) delete linlin where age>=20
db.linlin.remove({'age':{$ne:20}}) delete linlin where age!=20

db.linlin.update({'name':'foobar'},{$set:{'age':36}}) update linlin set age=36 where name='foobar'
db.linlin.update({'name':'foobar'},{$inc:{'age':3}}) update linlin set age=age+3 where name='foobar'

官方提供的操作語(yǔ)句對(duì)照表:

上行:SQL 操作語(yǔ)句
下行:Mongo 操作語(yǔ)句
CREATE TABLE USERS (a Number, b Number)
db.createCollection("mycoll")

INSERT INTO USERS VALUES(1,1)
db.users.insert({a:1,b:1})

SELECT a,b FROM users
db.users.find({}, {a:1,b:1})

SELECT * FROM users
db.users.find()

SELECT * FROM users WHERE age=33
db.users.find({age:33})

SELECT a,b FROM users WHERE age=33
db.users.find({age:33}, {a:1,b:1})

SELECT * FROM users WHERE age=33 ORDER BY name
db.users.find({age:33}).sort({name:1})

SELECT * FROM users WHERE age>33
db.users.find({'age':{$gt:33}})})

SELECT * FROM users WHERE age33
db.users.find({'age':{$lt:33}})})

SELECT * FROM users WHERE name LIKE "%Joe%"
db.users.find({name:/Joe/})

SELECT * FROM users WHERE name LIKE "Joe%"
db.users.find({name:/^Joe/})

SELECT * FROM users WHERE age>33 AND age=40
db.users.find({'age':{$gt:33,$lte:40}})})

SELECT * FROM users ORDER BY name DESC
db.users.find().sort({name:-1})

SELECT * FROM users WHERE a=1 and b='q'
db.users.find({a:1,b:'q'})

SELECT * FROM users LIMIT 10 SKIP 20
db.users.find().limit(10).skip(20)

SELECT * FROM users WHERE a=1 or b=2
db.users.find( { $or : [ { a : 1 } , { b : 2 } ] } )

SELECT * FROM users LIMIT 1
db.users.findOne()

SELECT DISTINCT last_name FROM users
db.users.distinct('last_name')

SELECT COUNT(*y) FROM users
db.users.count()

SELECT COUNT(*y) FROM users where AGE > 30
db.users.find({age: {'$gt': 30}}).count()

SELECT COUNT(AGE) from users
db.users.find({age: {'$exists': true}}).count()

CREATE INDEX myindexname ON users(name)
db.users.ensureIndex({name:1})

CREATE INDEX myindexname ON users(name,ts DESC)
db.users.ensureIndex({name:1,ts:-1})

EXPLAIN SELECT * FROM users WHERE z=3
db.users.find({z:3}).explain()

UPDATE users SET a=1 WHERE b='q'
db.users.update({b:'q'}, {$set:{a:1}}, false, true)

UPDATE users SET a=a+2 WHERE b='q'
db.users.update({b:'q'}, {$inc:{a:2}}, false, true)

DELETE FROM users WHERE z="abc"
db.users.remove({z:'abc'});
您可能感興趣的文章:
  • MongoDB常用操作命令大全
  • MongoDB各種查詢操作詳解
  • MongoDB中的一些坑(最好不要用)
  • Mongodb 忘記密碼的解決辦法
  • mongos崩潰后無(wú)法重啟問(wèn)題的解決方法

標(biāo)簽:丹東 景德鎮(zhèn) 吉安 鶴崗 本溪 邯鄲 大理 昭通

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《MongoDB 語(yǔ)法使用小結(jié)》,本文關(guān)鍵詞  MongoDB,語(yǔ)法,使用,小結(jié),MongoDB,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《MongoDB 語(yǔ)法使用小結(jié)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于MongoDB 語(yǔ)法使用小結(jié)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 灵寿县| 扶沟县| 岳阳县| 油尖旺区| 沅陵县| 泰顺县| 怀宁县| 龙井市| 西安市| 房山区| 通江县| 阜新| 德惠市| 新昌县| 中山市| 年辖:市辖区| 博白县| 马山县| 岳池县| 临夏市| 永定县| 大竹县| 韩城市| 江西省| 青州市| 靖安县| 东乌珠穆沁旗| 咸丰县| 穆棱市| 南雄市| 民县| 乌兰浩特市| 四会市| 根河市| 永顺县| 鱼台县| 喀喇沁旗| 巴楚县| 阳曲县| 宾阳县| 同江市|