1,客户端启动和服务端开启命令:
mongod 服务端
–dbpath
–port
–logpath
mongo 客户端
–port
–host
2,基础命令
show dbs
show collections
show tables
如何创建库?
1,use 数据库名
2,添加一条数据
db.collectionName.insert(文档)
db.createCollection(name)
删除数据库:db.dropDatabase()
删除集合:db.collectionName.drop()
3,增删改查 CRUD
(1)insert–插入
db.collectionName.insert([文档])
插入多条文档:
db.collectionName.insert([{文档1},{文档2},{文档3},…])
(2)查找–find
db.collectionName.find({查询表达式},{field1:1/0})–1显示,0不显示
查询表达式:
- {key:value}
< $lt
> $gt
<= $lte
>= $gte
!= $ne
{$nin:{age:[1,2,3]}} 查询不在数组中的数据
{$in:{age:[12,13,14]} 查询在数组中的数据
{$all:{hobby:['a','b','c']}} 满足数组中的所有内容的条件
{$mod:{age:[5,1]}
{$and:[{},{},{}]}
{$or:[{},{},{}]}
{$nor:[{},{},{}]}
(3)聚合