笔记8 mongo基础命令
一、基础命令 use test–选库 显示 switched to db test db.createCollection(‘goods’) 显示(‘ok’:1) show dbs 显示当前所有的库 use shop switched to db shop db.goods.insert({name:‘zhangsan’,age:9}) 显示writeResult({‘nInserted’:1}) show dbs–显示当前所有的库 2,查看数据库下面的集合 use shop switched to db shop show collections goods show tables goods 3,删除数据和删除集合 use test switched to db test db.dropDatabase() (“dropped”:“test”,“ok”:1) use shop switched to db shop db.goods.drop() true 二、CRUD命令 1、插入:insert 单条插入 db.stu.insert({name:‘lisi’,age:10,gender:1}) 显示 writeResult({“nInserted”:1})–成功 0则失败 _id字段自动创建,主键自动设置到这个字段 这个字段可手动指定,但不可重复 db.stu.find(