[ { _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’);
@martin823823 代码改一下格式吧,这样看着难受
要的 马上
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);
});
那我的代码,是出错在哪里呢???我还是没看出来,,能在详细点吗,,谢谢啊,,,这个问题困扰很多天了,,,
@martin823823 代码格式你再调整下吧
yaode
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’);
现在呢 你看看 要的不
你用的什么编辑器啊,我把你的代码复制进webstorm里面,很多错误,分号什么的,都用的中文符号
sublime text 这个
en 刚刚解决这个困扰几天的问题了 太好了 十分感谢哈
不好意思哈 我刚刚也复制了看看 结果还真是 错的多 可能是复制时出了问题
能好好编辑一下代码么?
```
@martin823823 所以是怎么回事? 自豪地采用 CNodeJS ionic
save那个方法有错 只把版本号与ID传到数据库了 填写的没有进去
@reverland save那个方法有错 只把版本号与ID传到数据库了 填写的没有进去
@i5ting 嗯嗯 要的 一定改进, 有没有好的推荐下 谢谢了
@martin823823 其实刚刚看了会儿没找到你的save… 自豪地采用 CNodeJS ionic
@martin823823 学学md语法就好,没啥难的
@i5ting 嗯嗯 要的