Mongoose创建的schema出错。

龙上 发布于 2013/05/06 21:38
阅读 622
收藏 0
var n = require('needle')
var $ = require('jquery').create()
var iconv = require('iconv').Iconv;
var lite = require('iconv-lite')
var mongoose = require('mongoose');
var async = require('async')
mongoose.connect('mongodb://localhost/cj');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
var question = []
var answer = []
//一。采集第一集分类的链接地址
var one = function(error,response,body){
    var content = new iconv('gbk','UTF-8//TRANSLIT//IGNORE').convert(new Buffer(body,'binary')).toString()
    //标题
    question['title'] = $(content).find('title').text()
    $.each($(content).find('.tboxs'),function(i,v){
        $(v).find('.anniu').nextAll().remove()
        $(v).find('.tousu').remove()
        $(v).find('.anniu').remove()
        var cc = $(v).find('.tbrig').html()//内容
        var a = $(v).find('.username').text()
        if(i == 0)
        {
            question['question'] = {content:cc,author:a}
        } else {
            answer.push({content:cc,author:a})
        }
    })
    console.log(question)
    db.once('open',function(){
        var m39 = mongoose.Schema({
            id:Number,//采集的地址
            date:{type:Date,default:Date.now},
            question:{
                content:String,
                author:String
            },
            answer:{
                id:{
                    content:String,
                    author:String
                }
            },
            url:String
        })
        var c_39_url = mongoose.model('c_39_url',m39)
    }
}



n.get('http://ask.39.net/question/24749283.html',{decode_response:false,encoding:'binary'},one)

出现的错误

D:\node.js\cj39.js:53
}
^
SyntaxError: Unexpected token }
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

加载中
返回顶部
顶部