Mongoose: Getting error while inserting document [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • mongoose .find() method returns object with unwanted properties

    2 answers



  • How can I display a JavaScript object?

    36 answers



  • log all queries that mongoose fire in the application

    4 answers



  • Mongoose find() not returning result

    1 answer




I am using mongoose in my node.js backend. I am setting this for the first time, and getting an error while inserting a document (this is my first call to MongoDB using mongoose).



Below are my files and code to connect with mongo:



app.js: It and dependency of a file mentioned below:



require('./lib/mongoDb')


mongoDb.js: It has all configurations which are required to connect with mongo



var mongoose = require('mongoose');
var Promise = require('bluebird');
var Step = require('step');
mongoose.Promise = Promise;
mongoose.connect('mongodb://user:password@localhost:27017/dbname', {
useCreateIndex: true,
useNewUrlParser: true
})


Model Schema for error_logs
error_logs.js: Schema defined for error_details



var mongoose = require('mongoose');

var default_schema = new mongoose.Schema({
error:{},
time:{type: Date, default: Date.now}
});


var errorModel = mongoose.model('error_details', default_schema);
module.exports = errorModel;


myServices.js: This is the file where I am getting error, and I thing I missed something important while configuring mongoose



var errorSchema = require('../model/error_logs');

var saveErrorLogs = (errorObj) => {
return new Promise((resolve, reject) => {
errorSchema.create({
error: errorObj
})
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
})
});
}

module.exports = {
saveErrorLogs: saveErrorLogs
}


I am getting following error in catch and unable to insert any document in collection:



    null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}
__v: 0
_doc: Object {_id: ObjectID, error: Object, time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard …, …}
_id: ObjectID
$__: InternalCache {strictMode: true, selected: undefined, shardval: undefined, …}
error: Object
errors: undefined
id: "5bf51315dc3c903258770ee4"
isNew: false
time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard Time)
__proto__: Model {db: NativeConnection, discriminators: undefined, error: <accessor>, …}
13:42:00
null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}


I am calling this service from a cron job
cronfile.js



const myServices= require('../../services/myServices');
const cron = require('node-cron');
cron.schedule("0 */1 * * * *", function () {
myServices.saveErrorLogs(error)
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
})
});


Can you guys please figure out what configuration error is in my code?



No new document is inserted in collection:



enter image description here



For reference:



enter image description here










share|improve this question















marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • console.log(JSON.stringify(result, undefined, 2)). These "Mongoose documents" are not just plain JavaScipt Objects with only the values you are expecting. The "stringify" will only print the values you expect.
    – Neil Lunn
    Nov 21 at 8:36










  • How this marked as duplicate @NeilLunn
    – Vaidya
    Nov 21 at 8:40










  • Yes you are. The output you are showing in the question is not an error. How about actually reading the comments and answers and trying the code before ranting back in comments. You are being given good advice about an issue many people have asked the same thing about before.
    – Neil Lunn
    Nov 21 at 8:40












  • @NeilLunn But when I check my collection there is no new document. Can you help me in finding what configuration I missed?
    – Vaidya
    Nov 21 at 8:42










  • mongoose.set("debug", true) and read the linked answers. This should take you at least a few hours
    – Neil Lunn
    Nov 21 at 8:44















up vote
-1
down vote

favorite













This question already has an answer here:




  • mongoose .find() method returns object with unwanted properties

    2 answers



  • How can I display a JavaScript object?

    36 answers



  • log all queries that mongoose fire in the application

    4 answers



  • Mongoose find() not returning result

    1 answer




I am using mongoose in my node.js backend. I am setting this for the first time, and getting an error while inserting a document (this is my first call to MongoDB using mongoose).



Below are my files and code to connect with mongo:



app.js: It and dependency of a file mentioned below:



require('./lib/mongoDb')


mongoDb.js: It has all configurations which are required to connect with mongo



var mongoose = require('mongoose');
var Promise = require('bluebird');
var Step = require('step');
mongoose.Promise = Promise;
mongoose.connect('mongodb://user:password@localhost:27017/dbname', {
useCreateIndex: true,
useNewUrlParser: true
})


Model Schema for error_logs
error_logs.js: Schema defined for error_details



var mongoose = require('mongoose');

var default_schema = new mongoose.Schema({
error:{},
time:{type: Date, default: Date.now}
});


var errorModel = mongoose.model('error_details', default_schema);
module.exports = errorModel;


myServices.js: This is the file where I am getting error, and I thing I missed something important while configuring mongoose



var errorSchema = require('../model/error_logs');

var saveErrorLogs = (errorObj) => {
return new Promise((resolve, reject) => {
errorSchema.create({
error: errorObj
})
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
})
});
}

module.exports = {
saveErrorLogs: saveErrorLogs
}


I am getting following error in catch and unable to insert any document in collection:



    null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}
__v: 0
_doc: Object {_id: ObjectID, error: Object, time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard …, …}
_id: ObjectID
$__: InternalCache {strictMode: true, selected: undefined, shardval: undefined, …}
error: Object
errors: undefined
id: "5bf51315dc3c903258770ee4"
isNew: false
time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard Time)
__proto__: Model {db: NativeConnection, discriminators: undefined, error: <accessor>, …}
13:42:00
null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}


I am calling this service from a cron job
cronfile.js



const myServices= require('../../services/myServices');
const cron = require('node-cron');
cron.schedule("0 */1 * * * *", function () {
myServices.saveErrorLogs(error)
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
})
});


Can you guys please figure out what configuration error is in my code?



No new document is inserted in collection:



enter image description here



For reference:



enter image description here










share|improve this question















marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • console.log(JSON.stringify(result, undefined, 2)). These "Mongoose documents" are not just plain JavaScipt Objects with only the values you are expecting. The "stringify" will only print the values you expect.
    – Neil Lunn
    Nov 21 at 8:36










  • How this marked as duplicate @NeilLunn
    – Vaidya
    Nov 21 at 8:40










  • Yes you are. The output you are showing in the question is not an error. How about actually reading the comments and answers and trying the code before ranting back in comments. You are being given good advice about an issue many people have asked the same thing about before.
    – Neil Lunn
    Nov 21 at 8:40












  • @NeilLunn But when I check my collection there is no new document. Can you help me in finding what configuration I missed?
    – Vaidya
    Nov 21 at 8:42










  • mongoose.set("debug", true) and read the linked answers. This should take you at least a few hours
    – Neil Lunn
    Nov 21 at 8:44













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • mongoose .find() method returns object with unwanted properties

    2 answers



  • How can I display a JavaScript object?

    36 answers



  • log all queries that mongoose fire in the application

    4 answers



  • Mongoose find() not returning result

    1 answer




I am using mongoose in my node.js backend. I am setting this for the first time, and getting an error while inserting a document (this is my first call to MongoDB using mongoose).



Below are my files and code to connect with mongo:



app.js: It and dependency of a file mentioned below:



require('./lib/mongoDb')


mongoDb.js: It has all configurations which are required to connect with mongo



var mongoose = require('mongoose');
var Promise = require('bluebird');
var Step = require('step');
mongoose.Promise = Promise;
mongoose.connect('mongodb://user:password@localhost:27017/dbname', {
useCreateIndex: true,
useNewUrlParser: true
})


Model Schema for error_logs
error_logs.js: Schema defined for error_details



var mongoose = require('mongoose');

var default_schema = new mongoose.Schema({
error:{},
time:{type: Date, default: Date.now}
});


var errorModel = mongoose.model('error_details', default_schema);
module.exports = errorModel;


myServices.js: This is the file where I am getting error, and I thing I missed something important while configuring mongoose



var errorSchema = require('../model/error_logs');

var saveErrorLogs = (errorObj) => {
return new Promise((resolve, reject) => {
errorSchema.create({
error: errorObj
})
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
})
});
}

module.exports = {
saveErrorLogs: saveErrorLogs
}


I am getting following error in catch and unable to insert any document in collection:



    null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}
__v: 0
_doc: Object {_id: ObjectID, error: Object, time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard …, …}
_id: ObjectID
$__: InternalCache {strictMode: true, selected: undefined, shardval: undefined, …}
error: Object
errors: undefined
id: "5bf51315dc3c903258770ee4"
isNew: false
time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard Time)
__proto__: Model {db: NativeConnection, discriminators: undefined, error: <accessor>, …}
13:42:00
null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}


I am calling this service from a cron job
cronfile.js



const myServices= require('../../services/myServices');
const cron = require('node-cron');
cron.schedule("0 */1 * * * *", function () {
myServices.saveErrorLogs(error)
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
})
});


Can you guys please figure out what configuration error is in my code?



No new document is inserted in collection:



enter image description here



For reference:



enter image description here










share|improve this question
















This question already has an answer here:




  • mongoose .find() method returns object with unwanted properties

    2 answers



  • How can I display a JavaScript object?

    36 answers



  • log all queries that mongoose fire in the application

    4 answers



  • Mongoose find() not returning result

    1 answer




I am using mongoose in my node.js backend. I am setting this for the first time, and getting an error while inserting a document (this is my first call to MongoDB using mongoose).



Below are my files and code to connect with mongo:



app.js: It and dependency of a file mentioned below:



require('./lib/mongoDb')


mongoDb.js: It has all configurations which are required to connect with mongo



var mongoose = require('mongoose');
var Promise = require('bluebird');
var Step = require('step');
mongoose.Promise = Promise;
mongoose.connect('mongodb://user:password@localhost:27017/dbname', {
useCreateIndex: true,
useNewUrlParser: true
})


Model Schema for error_logs
error_logs.js: Schema defined for error_details



var mongoose = require('mongoose');

var default_schema = new mongoose.Schema({
error:{},
time:{type: Date, default: Date.now}
});


var errorModel = mongoose.model('error_details', default_schema);
module.exports = errorModel;


myServices.js: This is the file where I am getting error, and I thing I missed something important while configuring mongoose



var errorSchema = require('../model/error_logs');

var saveErrorLogs = (errorObj) => {
return new Promise((resolve, reject) => {
errorSchema.create({
error: errorObj
})
.then((result) => {
resolve(result);
})
.catch((err) => {
reject(err);
})
});
}

module.exports = {
saveErrorLogs: saveErrorLogs
}


I am getting following error in catch and unable to insert any document in collection:



    null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}
__v: 0
_doc: Object {_id: ObjectID, error: Object, time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard …, …}
_id: ObjectID
$__: InternalCache {strictMode: true, selected: undefined, shardval: undefined, …}
error: Object
errors: undefined
id: "5bf51315dc3c903258770ee4"
isNew: false
time: Wed Nov 21 2018 13:41:01 GMT+0530 (India Standard Time)
__proto__: Model {db: NativeConnection, discriminators: undefined, error: <accessor>, …}
13:42:00
null: model {$__: InternalCache, isNew: false, errors: undefined, _doc: Object}


I am calling this service from a cron job
cronfile.js



const myServices= require('../../services/myServices');
const cron = require('node-cron');
cron.schedule("0 */1 * * * *", function () {
myServices.saveErrorLogs(error)
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
})
});


Can you guys please figure out what configuration error is in my code?



No new document is inserted in collection:



enter image description here



For reference:



enter image description here





This question already has an answer here:




  • mongoose .find() method returns object with unwanted properties

    2 answers



  • How can I display a JavaScript object?

    36 answers



  • log all queries that mongoose fire in the application

    4 answers



  • Mongoose find() not returning result

    1 answer








node.js mongodb mongoose






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 8:44

























asked Nov 21 at 8:31









Vaidya

1791223




1791223




marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 21 at 8:34


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • console.log(JSON.stringify(result, undefined, 2)). These "Mongoose documents" are not just plain JavaScipt Objects with only the values you are expecting. The "stringify" will only print the values you expect.
    – Neil Lunn
    Nov 21 at 8:36










  • How this marked as duplicate @NeilLunn
    – Vaidya
    Nov 21 at 8:40










  • Yes you are. The output you are showing in the question is not an error. How about actually reading the comments and answers and trying the code before ranting back in comments. You are being given good advice about an issue many people have asked the same thing about before.
    – Neil Lunn
    Nov 21 at 8:40












  • @NeilLunn But when I check my collection there is no new document. Can you help me in finding what configuration I missed?
    – Vaidya
    Nov 21 at 8:42










  • mongoose.set("debug", true) and read the linked answers. This should take you at least a few hours
    – Neil Lunn
    Nov 21 at 8:44


















  • console.log(JSON.stringify(result, undefined, 2)). These "Mongoose documents" are not just plain JavaScipt Objects with only the values you are expecting. The "stringify" will only print the values you expect.
    – Neil Lunn
    Nov 21 at 8:36










  • How this marked as duplicate @NeilLunn
    – Vaidya
    Nov 21 at 8:40










  • Yes you are. The output you are showing in the question is not an error. How about actually reading the comments and answers and trying the code before ranting back in comments. You are being given good advice about an issue many people have asked the same thing about before.
    – Neil Lunn
    Nov 21 at 8:40












  • @NeilLunn But when I check my collection there is no new document. Can you help me in finding what configuration I missed?
    – Vaidya
    Nov 21 at 8:42










  • mongoose.set("debug", true) and read the linked answers. This should take you at least a few hours
    – Neil Lunn
    Nov 21 at 8:44
















console.log(JSON.stringify(result, undefined, 2)). These "Mongoose documents" are not just plain JavaScipt Objects with only the values you are expecting. The "stringify" will only print the values you expect.
– Neil Lunn
Nov 21 at 8:36




console.log(JSON.stringify(result, undefined, 2)). These "Mongoose documents" are not just plain JavaScipt Objects with only the values you are expecting. The "stringify" will only print the values you expect.
– Neil Lunn
Nov 21 at 8:36












How this marked as duplicate @NeilLunn
– Vaidya
Nov 21 at 8:40




How this marked as duplicate @NeilLunn
– Vaidya
Nov 21 at 8:40












Yes you are. The output you are showing in the question is not an error. How about actually reading the comments and answers and trying the code before ranting back in comments. You are being given good advice about an issue many people have asked the same thing about before.
– Neil Lunn
Nov 21 at 8:40






Yes you are. The output you are showing in the question is not an error. How about actually reading the comments and answers and trying the code before ranting back in comments. You are being given good advice about an issue many people have asked the same thing about before.
– Neil Lunn
Nov 21 at 8:40














@NeilLunn But when I check my collection there is no new document. Can you help me in finding what configuration I missed?
– Vaidya
Nov 21 at 8:42




@NeilLunn But when I check my collection there is no new document. Can you help me in finding what configuration I missed?
– Vaidya
Nov 21 at 8:42












mongoose.set("debug", true) and read the linked answers. This should take you at least a few hours
– Neil Lunn
Nov 21 at 8:44




mongoose.set("debug", true) and read the linked answers. This should take you at least a few hours
– Neil Lunn
Nov 21 at 8:44

















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...