当前位置:数据库 > DB2 >>

MongoDB使用总结系列2

MongoDB使用总结系列2
 
由于习惯了使用关系型数据库,觉得SQL语句对数据进行操作的灵活性不用多说,也很好理解和掌握,但是开始用MongoDB后,在客户端命令行中对一些数据进行操作时总是很别扭,总是提示语法错误,尽管RockMongo或MongoVUE等工具 提供了很多便利,但有些操作还是需要命令行操作,于是将在命令行中的数据操作命令做了个大概的总结:
1.查看命令提示
db.help();
db.collname.help();
db.collname.find().help();
re.help();
2.切换创建数据库
use dbname;
3.查询所有数据库
show dbs;
4.删除当前使用的数据库
db.dropDataBase();
5.创建集合(table)
db.createCollection("name",{size:1,capped:5,max:100});
6.查询
db.table.find() 相当于:select * from table
db.table.distinct("name") 相当于:select distinct name from table;
db.table.find({"age":22}) 相当于:select * from table where age=22;
db.table.find({"age":{$gte:22}}) 相当于 select * from table where age>=22;
db.table.find({"age":{$lt:22}}) 相当于 select * from table where age<22;
db.table.find({"age":22},{"name":1}) 相当于 select name from table where age=22
db.table.find({"age":{$gt:10,$lt:30}}) 相当于 select * from table  where age>10 and age<=30
db.table.find({"name":/mary/});相当于 select * from table where name like '%mary%'
7.新增
db.table.save({name:1,age:1}); 相当于insert into table (name,age) values (1,1);
8.修改
db.table.update({age:1},{$set:{name:mary}},false,true) 相当于update table set name=mary where age=1
9.删除
db.table.remove({age:1}) 相当于 delete from table where age=1
 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,