# mongodb **Repository Path**: dingmochou/mongodb ## Basic Information - **Project Name**: mongodb - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-02-24 - **Last Updated**: 2021-03-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 1. ``` show dbs use jike //切换到了jike这个数据库 db.user.insert({"name":"cheng"}) show collections //显示有几张表 ``` > Tips:表的首字符以英文开头 ``` //增,删,改,查 增加 insert 删除 remove 修改 查 find ``` ## 1 查询 ``` //进入某个具体的数据 db.user.find() select * from user //sql db.getCollection("user").find(); ``` ``` //条件查询 //gt gather than 大于 //lt less than 小于 db.getCollection("01class").find({age:{$gt:18}}) ``` #### 1-1 升序降序 ``` db.getCollection("01class").find().sort({age:1}); //升序 db.getCollection("01class").find().sort({age:-1}); //降序 ``` #### 1-2 条件查询 ``` //一个条件的查询 db.getCollection("01class").find({id:1001}); //只会返回id为1001 ``` #### 1-3 模糊查询 ``` db.top250.find({name:/你/}) ``` ``` 根据分数对top250 这张表进行降序 ``` ## 2 删除 ``` db.user.remove({name:"lisi"}) db.user.deleteOne({name:"lisi"}) ``` ## 3 修改 ``` db.top250.update({name:"你的名字"},{$set:{name:"你好"}}) ``` ``` db.top250.update({name:"你好"},{name:"你的名字"}) ```