V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
martin823823
V2EX  ›  Node.js

不能把数据导入 mongodb( 3.0) 填写的信息能在控制台上显示出来,就是不能导入

  •  
  •   martin823823 · 2015-08-28 12:47:38 +08:00 · 2901 次点击
    这是一个创建于 3374 天前的主题,其中的信息可能已经有所发展或是发生改变。
    /**
    * Module dependencies.
    */

    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/test');


    var Schema = mongoose.Schema;
    var ObjectId = Schema.ObjectId;

    var Task = new Schema ({
    task: {type:String}
    });

    var Task = db.model ('Task', 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 (req.body.task );

    task.save (function (err ) {
    if (!err ) {
    res.redirect ('/tasks');
    }
    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');
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1044 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 19:34 · PVG 03:34 · LAX 11:34 · JFK 14:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.