mongodb数据库操作语法
来源:互联网 发布:java多线程用法 编辑:程序博客网 时间:2024/06/05 15:02
01
mongo–path
02
db.AddUser(username,password)
03
db.auth(usrename,password)
04
db.cloneDatabase(fromhost)
05
db.commandHelp(name)
help
for
thecommand
06
db.copyDatabase(fromdb,todb,fromhost)
07
db.createCollection(name,{size:
3333
,capped:
333
,
max
:
88888
})
08
db.currentOp()
09
db.dropDatabase()
10
db.
eval
(func,args)
-
side
11
db.getCollection(cname)
'cname'
]
or
db.cname
12
db.getCollenctionNames()
13
db.getLastError()
14
db.getLastErrorObj()
15
db.getMongo()
object
16
db.getMondo().setSlaveOk()
from
thennonmaster membr of a replica pair
17
db.getName()
18
db.getPrevError()
19
db.getProfilingLevel()
20
db.getReplicationInfo()
21
db.getSisterDB(name)
22
db.killOp()
23
db.printCollectionStats()
24
db.printReplicationInfo()
25
db.printSlaveReplicationInf
26
db.printShardingStatus()
27
db.removeUser(username)
28
db.repairDatabase()
29
db.resetError()
30
db.runCommand(cmdObj)
if
cmdObj
is
astring, turns it into{cmdObj:
1
}
31
db.setProfilingLevel(level)
0
=
off,
1
=
slow,
2
=
all
32
db.shutdownServer()
33
db.version()
数据集(表)操作语法
01
db.linlin.find({
id
:
10
})
ID
=
10
的数据集
02
db.linlin.find({
id
:
10
}).count()
ID
=
10
的数据总数
03
db.linlin.find({
id
:
10
}).limit(
2
)返回linlin数据集
ID
=
10
的数据集从第二条开始的数据集
04
db.linlin.find({
id
:
10
}).skip(
8
)
ID
=
10
的数据集从
0
到第八条的数据集
05
db.linlin.find({
id
:
10
}).limit(
2
).skip(
8
)
ID
=
1
=
的数据集从第二条到第八条的数据
06
db.linlin.find({
id
:
10
}).sort()
ID
=
10
的排序数据集
07
db.linlin.findOne([query])
08
db.linlin.getDB()
09
db.linlin.getIndexes()
10
db.linlin.group({key:…,initial:…,
reduce
:…[,cond:...]})
11
db.linlin.mapReduce(mayFunction,reduceFunction,)
12
db.linlin.remove(query)
13
db.linlin.renameCollection(newName)
14
db.linlin.save(obj)
15
db.linlin.stats()
16
db.linlin.storageSize()
17
db.linlin.totalIndexSize()
18
db.linlin.totalSize()
19
db.linlin.update(query,
object
[,upsert_bool])在此数据集中更新一条数据
20
db.linlin.validate()
21
db.linlin.getShardVersion()
22
db.linlin.find({‘name’:'foobar’})
*
from
linlin wherename
=
’foobar’
23
db.linlin.find()
*
from
linlin
24
db.linlin.find({‘
ID
’:
10
}).count()
*
)
from
linlinwhere
ID
=
10
25
db.linlin.find().skip(
10
).limit(
20
)
20
条数据
*
from
linlinlimit
10
,
20
———
-
mysql
26
db.linlin.find({‘
ID
’:{$
in
:[
25
,
35
,
45
]}})
*
from
linlinwhere
ID
in
(
25
,
35
,
45
)
27
db.linlin.find().sort({‘
ID
’:
-
1
})
*
from
linlinorderby
ID
desc
28
db.linlin.distinct(‘name’,{‘
ID
’:{$lt:
20
}})
from
linlinwhere
ID
<</code>
20
29
db.linlin.group({key:{‘name’:true},cond:{‘name’:'foo’},
reduce
:function(obj,prev){prev.msum
+
=
obj.marks;},initial:{msum:
0
}})
30
selectname,
sum
(marks)
from
linlingroup by name
31
db.linlin.find(‘this.
ID
<</code>
20′,{name:
1
})
from
linlinwhere
ID
<</code>
20
32
db.linlin.insert({‘name’:
'foobar’,'
age’:
25
})
25
)
33
db.linlin.insert({‘name’:
'foobar’,'
age’:
25
,’email’:'cclove2@
163.com
’})
34
db.linlin.remove({})
*
from
linlin
35
db.linlin.remove({‘age’:
20
})
=
20
36
db.linlin.remove({‘age’:{$lt:
20
}})
20
37
db.linlin.remove({‘age’:{$lte:
20
}})
=20
38
db.linlin.remove({‘age’:{$gt:
20
}})
20
39
db.linlin.remove({‘age’:{$gte:
20
}})
=
20
40
db.linlin.remove({‘age’:{$ne:
20
}})
=
20
41
db.linlin.update({‘name’:'foobar’},{$
set
:{‘age’:
36
}})
set
age
=
36
wherename
=
’foobar’
42
db.linlin.update({‘name’:'foobar’},{$inc:{‘age’:
3
}})
set
age
=
age
+
3
wherename
=
’foobar’
超级用户相关:
- useadmin
- #增加或修改用户密码
- db.addUser(ixigua,'pwd')
- #查看用户列表
- db.system.users.find()
- #用户认证
- db.auth(ixigua,'pwd')
- #删除用户
- db.removeUser('mongodb')
- #查看所有用户
- showusers
- #查看所有数据库
- showdbs
- #查看所有的collection
- showcollections
- #查看各collection的状态
- db.printCollectionStats()
- #查看主从复制状态
- db.printReplicationInfo()
- #修复数据库
- db.repairDatabase()
- #设置记录profiling,0=off 1=slow2=all
- db.setProfilingLevel(1)
- #查看profiling
- showprofile
- #拷贝数据库
- db.copyDatabase('mail_addr','mail_addr_tmp')
- #删除collection
- db.mail_addr.drop()
- #删除当前的数据库
- db.dropDatabase()
- 客户端连接
- /usr/local/mongodb/bin/mongo8.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':'Hello1'}).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()
- mongodb数据库操作语法
- mongodb数据库操作语法
- mongodb数据库操作语法
- mongodb数据库操作语法
- MongoDB:MongoDB数据库操作
- MongoDB 基本操作语法
- MongoDB数据库SQl语法
- 操作2:mongodb使用语法
- PHP操作Mongodb原生语法
- MongoDB 数据库操作类
- mongodb 数据库update 操作
- Mongodb数据库 操作语句
- mongodb数据库命令操作
- java 操作MongoDB数据库
- MongoDB 数据库操作
- MongoDB数据库常用操作
- java操作MongoDB数据库
- java操作MongoDB数据库
- Nodejs抓取非utf8字符编码的页面
- html div自适应动态上下左右居中
- jquery 结合css3使图片大小自适应
- transform使用参考
- 很不错的jquery讲解教程
- mongodb数据库操作语法
- 在Amazon服务器里管理用户
- ssh出现 permission denied (publickey)
- Node.Js 控制台和定时器(console &Timer)
- 在NodeJs中使用MongoDB中的MapReduce
- mongodb高级查询语法
- MongoDB中索引的创建和使用详解
- mongoDB大数据测试
- mongodb的监控与性能优化