I have tried everything I could think of but I'm still not able to insert any data into my MongoDB database. When receiving data (tweets) I log everything to check if the datatype matches the type of the field in my schema, which seems ok, but the data inserted into my database is just an empty mongodb document.
My schema:
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;
My model:
var mongoose = require("mongoose");
var tweetSchema = require("../schemas/tweet.js");
var Tweet = mongoose.model('Tweet',tweetSchema,"tweets");
module.exports = Tweet;
The part of my app where I try to insert the Document into my 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);
});
The log I'm receiving of the datatypes and content:
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
I don't get any errors but the Document inserted into my database is the following (which is just an empty mongoDB document):
{ __v: 0, _id: 54a9b1ba0114720c2711cbfc }
twdata?