I am trying to save data in MongoDB with Mongoose with Express.JS 4 and Bluebird .
I did like this:
bin / www
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
.......
.......
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function()
{
console.log("Successfully Connected to Mongo-DB");
});
And having received it in the console -
Successfully Connected to Mongo-DB` - So, MongoDB connected successfully
models /post.js
var mongoose = require('mongoose');
var postSchema = new mongoose.Schema({
created_by: String,
created_at: {type: Date, default: Date.now},
text: String
});
module.exports = mongoose.model('Post', postSchema);
app.js
var Post_Data = require("./models/post");
....
....
router.get('/', function(req, res, next)
{
var Post = mongoose.model("Post");
var post = new Post({
created_by: ""+Math.random()
});
console.log( Post.create(post) );
res.render(
'index',
{
title : 'Express',
site_name : 'Our Site',
layout : 'templates/layout'
}
);
});
And after that I get this in the console -
Promise {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined }
But nothing is saved , the evidence for this is
I find it -

After using MongoBooster .
Update -
My DB configuration is as follows:
"MONGO_URI": "mongodb://localhost:27017/express_test",
"MONGO_OPTIONS": {
"db": { "safe": true },
"name":"express_test"
}
So can anyone help, why is he not saving anything?
Thanks in advance for your help.