Skip to content

Commit

Permalink
mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
lihongmi committed Oct 26, 2017
1 parent f07cca0 commit 86b65cd
Show file tree
Hide file tree
Showing 29 changed files with 337 additions and 3 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ code/0502/node_modules
code/0502/images
code/0503/node_modules
code/0504/node_modules
code/0505/myapp1/node_modules
code/0505/myapp2/node_modules
code/0505/myapp3/node_modules
code/0601/myapp1/node_modules
code/0601/myapp2/node_modules
code/0601/myapp3/node_modules
code/0705/node_modules
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions code/0701/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!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>
// 描述数据的格式 text json xml



var students=[
{name:"xiaozhang",age:21,sex:0},
{name:"xiaozhang",age:21,sex:0},
{name:"xiaoA",age:23,sex:1}
];



<students>
<student sex="0">
<name>小张</name>
<age>21</age>
</student>
<student></student>
<student></student>

</students>


</body>
</html>
49 changes: 49 additions & 0 deletions code/0705/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

var Student =require("./model/Student");

//添加数据
/*var wujian=new Student({name:"wujian",age:31,sex:"男"});
var liuziun=new Student({name:"liu",age:21,sex:"女"});
var xuxiangke=new Student({name:"xu",age:11,sex:"男"});
wujian.save();
liuziun.save();
xuxiangke.save();*/


//查询数据
/*Student.find(function (err, students) {
if (err) return console.error(err);
console.log(students);
});
Student.find({ name: "liu" }, function (err, students) {
if (err) return console.error(err);
console.log(students);
});
Student.findByName("liu",function(err,data){
console.log(data);
});
*/

//修改数据
/*Student.update({ age: { $gt: 20 } }, { age: 25 }, {multi: true }, function(err){
if (err) return console.error(err);
console.log("修改成功");
});*/

//删除数据
Student.remove({ _id: '59f161f7154ae10fd427bb70' }, function (err) {
if (err) return handleError(err);
console.log("removed!");
});









19 changes: 19 additions & 0 deletions code/0705/model/Student.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/student', { useMongoClient: true });
mongoose.Promise = global.Promise;

var studentSchema = mongoose.Schema({
name: String,
age:Number,
sex:String
});

studentSchema.statics.findByName = function(name, cb) {
return this.find({ name: new RegExp(name, 'i') }, cb);
};

var Student = mongoose.model('Student', studentSchema);


module.exports=Student;

216 changes: 216 additions & 0 deletions code/0705/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions code/0705/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "0705",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mongoose": "^4.12.4"
}
}

0 comments on commit 86b65cd

Please sign in to comment.