mongo笔记

1:基本操作

use admin

db.createUser({user:"lxc",pwd:"123456",roles:['root']})

修改密码

db.changeUserPassword("username","newpassword")

查看用户信息

db.runCommand({userInfo:"kangw"})

验证用户

db.auth("username","pwd")

创建索引 db.users.ensureIndex({name:1}) db.users.ensureIndex( { "user_id" : 1, "person" : 1 } );

删除索引 db.users.dropIndexes("user_id")

插入记录 db.users.insert({a:1, b:1})

条件查询 db.users.find({'age':{gt:33,gt:33,lte:40}})

获取表记录数 Db.users.count()

删除记录 db.users.remove({z:'abc'}) 清空表 db.users.remove({})

删除表 db.users.drop()

创建表  db.createCollection("email_content");

显示表 show collections 

导出数据库 mongorestore -h 127.0.0.1 -d mongotest -u mongotest -p mongotest1qaz --dir /home/www/mongorestore-2017-04-06/mongotest

导入数据库 mongorestore -h 127.0.0.1 -d mongotest -u mongotest-p mongotest1qaz --dir /home/www/mongorestore-2017-04-06/mongotest 


2:数据库配置主要事项:

   1):缩进格式要统一不能乱写;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 姓名:于川皓 学号:16140210089 转载自:https://baike.baidu.com/item/sq...
    道无涯_cc76阅读 1,984评论 0 2
  • Mongodb 配置选项 通常在mongod.conf中 配置文件 设置了配置文件后启动时以自定义的配置文件启动:...
    AkaTBS阅读 1,098评论 0 6
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • 1.创建文件夹 !/bin/sh mkdir -m 777 "%%1" 2.创建文件 !/bin/sh touch...
    BigJeffWang阅读 10,222评论 3 53
  • show dbs:显示数据库列表 show collections:显示当前数据库中的集合(类似关系数据库中的表)...
    Weiliam阅读 7,434评论 0 2