下载mongodb安装包并解压下载地址 创建一个data和log文件夹(随意哪个盘都可以) 配置系统环境变量path(目的是执行起来方便) 将MongoDB服务做成一个window服务
mongo -logpath F:\mongodb\log\mongo.log –logappend –dbpath F:\mongodb\data –serviceName MongoDB –install 启动MongoDB服务
net start MongoDB 启动MongoDB客户端
mongo
操作 | oracle | mongodb |
---|---|---|
新建数据库 | 安装时创建 | use命令 切换/新建 数据库 |
删除数据库 | 使用DBCA图形化界面来进行 | db.dropDatabase() |
新建表(集合) | create table t_name() | use collection_name |
删表 | alter table t_name drop(column) | db.collection.drop() |
增 | insert into t_name() values() | db.collection.insert() |
删 | delete from t_name where ** | db.collection.remove() |
改 | update t_name set ziduan=** where | db.collection.update() |
查 | select * from t_name where ** | db.collection.find() |
排序 | order by * asc/desc | db.collection.find().sort() |
分页 | rownum | db.collection.find().skip().limit() |
and | and | 没有对应字段 |
or | or | $or |
in | in | $in |
not in | not in | $nin |
> | > | $gt |
< | < | $lt |
<= | <= | $lte |
= | = | 无对应字段 |
/参数为{}代表删除所有数据且不可回滚,参数为BSON代表删除一个/
db.collection.remove();
/**/
db.collection.update(
query, /查询条件/
update, /更新的对象以及一些更新操作符(
{
upsert:boolean,/默认false,true–如果此数据不存在则插入,否则不插入/
multi:boolean,
writeConcern:document
}
);