[ { _id: 55e0299f18c4f926021f92c5, __v: 0 }, { _id: 55e02bac646d663702241864, __v: 0 }, { _id: 55e02f4d3548405302885bbc, __v: 0 }, { _id: 55e0fcb4af32c4c001590735, __v: 0 }, { _id: 55e0fd498455c6c901ff9092, __v: 0 }, { _id: 55e10167290c50e201a8f111, __v: 0 }, { _id: 55e101dd62a8e2e3019ffc67, __v: 0 } ]
node app.js 就是把注册信息提交到数据库,但查不到提交的,就只能查到这个
macdeMacBook-Pro:uo mac$ node 07.js
the project run 3000
{ task: ‘wfwfwf’ }
能过在控制台看到
/**
- Module dependencies. */ var bson = require(“bson”); var model = require(‘model’); var express = require (‘express’), routes = require (‘./routes’), http = require (‘http’), path = require (‘path’), mongoose = require (‘mongoose’);
var bodyParser = require(‘body-parser’)
var app = express (); var db = mongoose.createConnection (‘mongodb://localhost/yohu’);
var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId;
var Task = new Schema ({ task: {type:String} },{ collection:’test’ },{ read: 'secondaryPreferred’});
var Task= db.model ('test’, Task );
// all environments
app.set ('view engine’, ‘jade’);
// parse application/x-www-form-urlencoded app.use (bodyParser.urlencoded ({ extended: false }))
// parse application/json app.use (bodyParser.json ())
app.get ('/tasks’, function (req, res ){ Task.find ({}, function (err, docs ) { res.render ('tasks/index’, { title: 'Todos index view’, docs: docs }); }); });
app.get ('/tasks/new’, function (req, res ){ res.render ('tasks/new.jade’, { title: ‘New Task’ }); });
app.post ('/tasks’,function (req, res ){ var task = new Task({name:req.body.task});
task.save (function (err ) { if (err ) { throw err; } else { res.redirect (‘/tasks/new’); } }); console.log (req.body ); });
app.listen (3000,function (err ){ if (err ){ console.log (err ); return err; } }); console.log (‘the project run 3000’);
var bson = require(“bson”); var model = require(‘model’); var express = require (‘express’), routes = require (‘./routes’), http = require (‘http’), path = require (‘path’), mongoose = require (‘mongoose’), bodyParser = require(‘body-parser’);
var app = express ();
var db = mongoose.createConnection (‘mongodb://localhost/yohu’);
var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId;
var Task = new Schema ({ task: {type:String} }, { collection:’test’ }, { read: 'secondaryPreferred’});
var Task= db.model ('test’, Task );
app.set ('view engine’, ‘jade’); app.use (bodyParser.urlencoded ({ extended: false }))
app.use (bodyParser.json ())
app.get ('/tasks’, function (req, res ){ Task.find ({}, function (err, docs ) { res.render ('tasks/index’, { title: 'Todos index view’, docs: docs }); }); });
app.get ('/tasks/new’, function (req, res ){ res.render ('tasks/new.jade’, { title: ‘New Task’ }); }); app.post ('/tasks’,function (req, res ){ var task = new Task({name:req.body.task});
task.save (function (err ) { if (err ) { throw err; } else { res.redirect (‘/tasks/new’); } }); console.log (req.body ); }); app.listen (3000,function (err ){ if (err ){ console.log (err ); return err; } }); console.log (‘the project run 3000’);
@martin823823 不是这样改,看看markdown的写法吧,改完后预览下看成功没得,像这样的效果
var UserModel = require('../GSAtlantis.srv/lib/models').UserModel;
UserModel.findOne(function (err, user) {
console.log(user);
});
var bson = require(“bson”); var model = require(‘model’); var express = require (‘express’), routes = require (‘./routes’), http = require (‘http’), path = require (‘path’), mongoose = require (‘mongoose’), bodyParser = require(‘body-parser’);
var app = express ();
app.set ('view engine’, ‘jade’); app.use (bodyParser.urlencoded ({ extended: false })) app.use (bodyParser.json ())
var db = mongoose.createConnection (‘mongodb://localhost/yohu’); var Schema = mongoose.Schema; var ObjectId = Schema.ObjectId; var Task = new Schema ( {task:String}, {collection:’test’});
var Task= db.model ('test’, Task );
app.get ('/tasks’, function (req, res ){ Task.find ({}, function (err, docs ) { res.render ('tasks/index’, { title: 'Todos index view’, docs: docs }); }); });
app.get ('/tasks/new’, function (req, res ){ res.render ('tasks/new.jade’, { title: ‘New Task’ }); });
app.post ('/tasks’,function (req, res ){ var task= new Task({name:req.body.task}); task.save(function (err ) { if (err ) { throw err; } else { res.redirect (‘/tasks/new’); } }); console.log (req.body ); });
app.listen (3000,function (err ){ if (err ){ console.log (err ); return err; } }); console.log (‘the project run 3000’);