-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
506 changed files
with
123,014 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
mongodb | ||
|
||
数据库: | ||
关系型数据库 | ||
mysql 数据库 表 | ||
orancel DBA | ||
非关系型数据库 | ||
[ | ||
{ | ||
"name":"4545" | ||
} | ||
] | ||
|
||
mongodb nosql sqlserver | ||
mongodb: 文档 集合 | ||
面向文档(document) | ||
{ | ||
"name":"333" | ||
} | ||
show dbs 查看当前的所有数据库 | ||
use admin 使用数据库 | ||
show collections 查看当前数据库下面的集合 | ||
db 查看当前选中的数据库 | ||
db.集合名.insert({}) 创建集合 | ||
增 | ||
insert | ||
db.集合名.insert({}) 插入单条 | ||
db.集合名.insert([{},{}]) 插入多条 | ||
db.集合名.insertOne({}) 插入单条 | ||
db.集合名.insertMany([]) 插入多条 | ||
删 | ||
remove | ||
db.集合名.remove({}) 删除所有 | ||
db.集合名.remove({"name":"tom"}) 删除指定的数据 | ||
delete | ||
db.集合名.deleteOne() 删除单个 | ||
db.集合名.deleteMany() 删除多个 | ||
update 修改 | ||
{"name":"tom","age":12} | ||
db.集合名.update({"name":"tom"},{$set:{"name":"jack"}}) 更新 | ||
db.集合名.update({"name":"tom"},{"name":"jack"}) | ||
{"name":"jack"} | ||
查 | ||
find | ||
db.集合名.findOne() 查询单个数据 | ||
pretty() 数据格式化 | ||
limit() 截取 长度 几条 | ||
skip () 跳过当前数据 数字 从第几条开始 | ||
创建集合 | ||
两种 | ||
db.createCollection("集合名",options) | ||
db.student.insert() | ||
删除当前数据库 | ||
db.dropDatabase() | ||
删除集合 | ||
db.集合名.drop() | ||
|
||
<div class="pagation"> | ||
<ul> | ||
<li>1</li> | ||
<li>2</li> | ||
<li>3</li> | ||
<li>4</li> | ||
<li>5</li> | ||
</ul> | ||
</div> | ||
$.ajax({ | ||
url:"http://127.0.0.1:3000/list", | ||
type:"get", | ||
dataType:"json", | ||
settimeout:3000, | ||
data:{ | ||
pageSize: //页数 | ||
pageNum: //每页显示的条数 | ||
} | ||
}).done(function(result){ | ||
<!-- result count 总数 7 --> | ||
var pageSize=Math.ceil(count/pageNum) | ||
循环 | ||
$(".pageation").html("<li click="aa(i)"></li>") | ||
}) | ||
|
||
条件语句 | ||
$gt 大于 $gte $lt 小于 $lte $ne 不等于 $and 并且 $or 或者 | ||
排序: | ||
sort() 1 正序 -1 倒序 | ||
作业: | ||
插入文件 | ||
mongoimport --db 数据库名称 --collection 集合名称 --file 文件路径 | ||
|
||
数据类型 | ||
聚合 | ||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ app.listen(3000) | |
// express-session | ||
// git | ||
// mongodb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var express=require("express") | ||
// mongodb | ||
// 引入mongodb的客户端 | ||
var mongoClient=require("mongodb").MongoClient | ||
var app=express() | ||
app.get("/add",(req,res)=>{ | ||
// 客户端连接服务端 | ||
mongoClient.connect("mongodb://127.0.0.1:27017",(err,db)=>{ | ||
// 连接数据库 | ||
var dbName=db.db("test") | ||
// 查找 | ||
// dbName.collection("data").find({"name":"tom"}).toArray((err,data)=>{ | ||
// res.send(data) | ||
// }) | ||
// 针对集合操作 插入 | ||
// dbName.collection("data").insert({"name":"jack"},(err,data)=>{ | ||
// // console.log(data) | ||
// res.send(data) | ||
// }) | ||
//更新 | ||
// dbName.collection("data").update({"name":"jack"}, | ||
// {$set:{"name":"jacks"}},(err,data)=>{ | ||
// res.send(data) | ||
// }) | ||
// 删除 | ||
dbName.collection("data").deleteOne({"name":"jacks"},(err,data)=>{ | ||
if(err){ | ||
throw err | ||
} | ||
res.send({"success":"删除成功"}) | ||
}) | ||
}) | ||
|
||
}) | ||
app.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 登录 注册 | ||
var express=require("express") | ||
var router=express.Router() | ||
var bodyparser=require("body-parser") | ||
var app=express() | ||
app.use(bodyparser.json()) | ||
app.use(bodyparser.urlencoded({extended:false})) | ||
app.use(router) | ||
var mongoClient=require("mongodb").MongoClient | ||
// 注册 | ||
router.post("/register",(req,res)=>{ | ||
mongoClient.connect("mongodb://127.0.0.1:27017",(err,db)=>{ | ||
var dbName=db.db("store") | ||
var data={ | ||
username:req.body.username, | ||
password:req.body.password, | ||
email:req.body.email, | ||
phone:req.body.phone, | ||
} | ||
dbName.collection("course").insert(data,(err,data)=>{ | ||
res.send({"success":"注册成功"}) | ||
}) | ||
}) | ||
}) | ||
// 登录 | ||
router.post("/login",(req,res)=>{ | ||
mongoClient.connect("mongodb://127.0.0.1:27017",(err,db)=>{ | ||
var dbName=db.db("store") | ||
var person={ | ||
username:req.body.username, | ||
password:req.body.password | ||
} | ||
dbName.collection("course").find({}).toArray((err,data)=>{ | ||
if(err) throw err | ||
if(person.username==data[0].username&&person.password==data[0].password){ | ||
res.send({"success":"登陆成功"}) | ||
}else{ | ||
res.send({"fail":"登录失败"}) | ||
} | ||
}) | ||
}) | ||
}) | ||
app.listen(3000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<form action="http://127.0.0.1:3000/register" method="post"> | ||
用户名<input type="text" name="username"/> | ||
密码<input type="text" name="password"/> | ||
邮箱<input type="text" name="email"/> | ||
手机<input type="text" name="phone"/> | ||
<input type="submit" value="提交"/> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<form action="http://127.0.0.1:3000/login" method="post"> | ||
用户名<input type="text" name="username"/> | ||
密码<input type="text" name="password"/> | ||
<input type="submit" value="登陆"/> | ||
</form> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.