MongoDB数据库常用指令汇总

来源:互联网 发布:淘宝上怎么买流量 编辑:程序博客网 时间:2024/05/18 00:16
MongoDB基本操作指南:启动MongDB服务:$ sudo service mongodb start进入 MongoDB 命令:$ mongo创建数据库:> use mydb查看当前连接的数据库:> db查看所有的数据库:> show dbs销毁数据库:> use localswitched to db local> db.dropDatabase()创建集合:> use mydbswitched to db mydb> db.createCollection("users")查看创建的集合:> show collections删除集合:> show collections> db.users.drop()insert插入数据:> use mydbswitched to db mydb> db.users.insert([... { name : "jam",... email : "jam@qq.com"... }... ])save插入数据:> use mydb2switched to db mydb2> db.users.save([... { name : "jam",... email : "jam@qq.com"... }... ])find查询语句:> db.post.find()> db.post.find().pretty()find条件查询语句:> db.users.find({ key1: value1, key2: value2 }).pretty()> db.post.find(    {      $or: [         {key1: value1}, {key2:value2}      ]    }).pretty()

原创粉丝点击