我正在尝试使用 node.js 填充我的 mongo db。但我收到一个 TypeError 说
' 对象 # 没有应用方法
.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
console.log('Running mongoose version %s:', mongoose.version);
var userSchema = Schema({
userName: String,
fullName: String,
email: String
});
var articleSchema = Schema({
name: String,
content_date: Date,
content: String,
author: String
});
var User = mongoose.model('User', userSchema);
var Article = mongoose.model('Article', articleSchema);
var createData = function () {
User.create({userName: 'mcslater', fullName: 'Ray Slater', email: 'r.slater@nomail'}, function (err, user) {
Article.create({
"name": "NEW YORK MAGAZINE",
"content": "Heaven, with hangers. <a href='http://nymag.com/fashion/08/fall/49258/index4.html' target='_blank'>New York Magazine</a> declares the MKG Wardrobe 'gorgeous' in the Fall Fashion '08 issue.",
"content_date": "Mon Aug 18 15:51:49 +0000 2008",
"author": user.userName
},
{
"name": "DWELL",
"content": "Michael Cannell of <a href='http://www.dwell.com' target='_blank'>Dwell</a> calls our work for the East 11th Townhouse 'artful' in a brief piece for Dwell.com.",
"content_date": "Tue June 17 12:00:00 +0000 2008",
"author": user.userName
},
{
"name": "DWELL",
"content": "The Josh & Donna Loft catches the eye of Michael Cannell at <a href='http://www.dwell.com' target='_blank'>Dwell.com</a>&nbps;.",
"content_date": "Tue Nov 27 12:00:00 +0000 2007",
"author": user.userName
},
{
"name": "ARCHITECTURAL RECORD",
"content": "Heavy metal, light touch. <a href='http://archrecord.construction.com/archrecord2/work/0710/associatedFabrication.asp' target='_blank'>Archrecord2</a> profiles 4-pli and our sister company, Associated Fabrication, in the October issue, out now.",
"content_date": "Mon Oct 8 12:00:00 +0000 2007",
"author": user.userName
},
{
"name": "OUR COTTON ANNIVERSARY",
"content": "On this day in history, way back in 2005, 4-pli was formed. Happy anniversary to us!",
"content_date": "Tue Oct 01 12:00:00 +0000 2007",
"author": user.userName
},
{
"name": "COOL HUNTING",
"content": "Our Nesting Desk makes the cut at Coolhunting.",
"content_date": "Wed Apr 04 12:00:00 +0000 2007",
"author": user.userName
})
})
};
mongoose.connect('localhost','news',function(err){
if(err) throw err;
createData();
});