nodejsとmonogoogleの検索と追加
1950 ワード
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/todo_delelopment');
var taskSchema = mongoose.Schema({
task: String
});
//schema
taskSchema.methods.speak = function () {
var greeting = this.task ? "Meow name is " + this.task : "I don't have a name";
console.log(greeting);
}
//
var task = mongoose.model('task', taskSchema);
var aTask = new task({ task: 'Silence' });
console.log(aTask.task) ;
aTask.save();
var taskNew = mongoose.model('task', taskSchema)
var task2 = new taskNew({ task: 'zhj22222l' });
task2.speak()
task2.save(function (err, task3) {
if (err) return console.error(err);
task3.speak();
});
taskNew.find(function (err, content) {
if (err) return console.error(err);
console.log(content)
})
// var Schema = mongoose.Schema;
// var ObjectId = Schema.ObjectId;
// var Task = new Schema({
// task : String
// });
// var Task = mongoose.model('Task',Task);
// /* GET users listing. */
// router.get('/tasks', function(req, res) {
// Task.find({},function(err,docs){
// res.render('tasks/index',{
// title:'tasks of me',
// docs:docs
// });
// // res.send(docs);
// });
// });
router.get('/new',function(req,res){
res.render('tasks/new',{
title:'new'
});
});
// router.post('/saveTask',function(req,res){
// var task = new Task(req.body.task);
// //res.send(req.body.task+'------');
// task.save(function(err){
// if (!err) {
// res.redirect('/tasks/tasks');
// }else{
// res.redirect('/tasks/new');
// }
// });
// });
module.exports = router;
nodejsとmonogoogleの検索と追加