无法使用mongoose,Node.js将数据插入到mongoDB中的Document的字段中

我已经尝试了所有我能想到的,但我仍然无法将任何数据插入到我的MongoDB数据库。 当接收到数据(tweets)时,我会logging所有的东西来检查数据types是否与模式中字段的types相匹配,这似乎没问题,但插入到数据库中的数据只是一个空的MongoDB文档。

我的模式:

var mongoose = require('mongoose'); var tweetSchema = new mongoose.Schema({ userName: {type: String, required: true}, imageUrl: {type: String}, bannerUrl: {type: String}, text: {type: String}, hashTag: {type: String} }); module.Exports = tweetSchema; 

我的模特:

 var mongoose = require("mongoose"); var tweetSchema = require("../schemas/tweet.js"); var Tweet = mongoose.model('Tweet',tweetSchema,"tweets"); module.exports = Tweet; 

我尝试将文档插入到我的mongoDB中的应用程序部分:

 var Twitter = require('node-tweet-stream'); require("./data/connectDB.js"); var Tweet = require('./data/models/tweet'); t.on('tweet', function(twdata){ var uName = twdata.user.screen_name.toString(); var iUrl = twdata.user.profile_image_url; var bUrl = twdata.user.profile_banner_url; var txt = twdata.text; var htag = "test"; console.log("username: " + uName + " - " + typeof uName); console.log("image url: " + iUrl + " - " + typeof iUrl); console.log("banner url: " + bUrl + " - " + typeof bUrl); console.log("text: " + txt + " - " + typeof txt); console.log("hashtag: " + htag + " - " + typeof htag); var newTweet = new Tweet({ userName: uName, imageUrl: iUrl, bannerUrl: bUrl, text: txt, hashTag: htag }); console.log(newTweet); newTweet.save(function(err, newTweet){ if(err){ console.log(err); } else{ console.dir(newTweet); } }); //console.log(twdata.id); }); 

我收到的数据types和内容的日志:

 username: ZBBXXR - string image url: http://pbs.twimg.com/profile_images/550347979886845953/9aU5othN_normal.jpeg - string banner url: https://pbs.twimg.com/profile_banners/274821783/1418814026 - string text: RT @NamiZelmon: happy birthday yoseob oppa💕💕💕🎂🎁🎉🎊 @all4b2uty hope you like this🙈 #HappyYSDay http://t.co/C6W3LFg5F5 - string hashtag: test - string 

我没有得到任何错误,但插入到我的数据库中的文档是以下(这只是一个空的mongoDB文档):

 { __v: 0, _id: 54a9b1ba0114720c2711cbfc } 

我不敢相信我没有看到这一个。 在我写的模式中

 module.Exports = tweetSchema; 

而应该是“出口”的非资本化

 module.exports = tweetSchema; 

由于大写字母错误,在./model/tweet.js中调用require('../ schema / tweet.js')时没有返回任何结果。 因此,传入未定义到“./model/tweet.js”中的mongoose.model('Tweet',TweetSchema,“tweets”)并创build空的数据库文档。