MongoError: write EPIPE - node.js

I'm using Node.JS + Mongoose + MongoDB. Had my app working ok until now, now when trying to save a document:
Saving operation:
doc.save(function(err, d){
console.log(err,d);
{"name":"MongoError","message":"write EPIPE"}
Error stack:
{ [MongoError: server localhost:27017 received an error {"name":"MongoError","message":"write EPIPE"}]
name: 'MongoError',
message: 'server localhost:27017 received an error {"name":"MongoError","message":"write EPIPE"}' } undefined
error: TypeError: Cannot read property 'url' of undefined
at EventEmitter.<anonymous> (/home/ec2-user/c/index.js:160:61)
at EventEmitter.<anonymous> (/home/ec2-user/c/node_modules/mongoose/node_modules/mpromise/lib/promise.js:174:48)
at EventEmitter.emit (events.js:95:17)
at Promise.safeEmit (/home/ec2-user/c/node_modules/mongoose/node_modules/mpromise/lib/promise.js:81:21)
at Promise.reject (/home/ec2-user/c/node_modules/mongoose/node_modules/mpromise/lib/promise.js:109:15)
at Promise.error (/home/ec2-user/c/node_modules/mongoose/lib/promise.js:94:15)
at Promise.resolve (/home/ec2-user/c/node_modules/mongoose/lib/promise.js:112:24)
at /home/ec2-user/c/node_modules/mongoose/lib/document.js:1555:39
at handleError (/home/ec2-user/c/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:40:22)
at next_ (/home/ec2-user/c/node_modules/mongoose/node_modules/hooks-fixed/hooks.js:75:26)
Looks like I'm able to read data, but not to write new documents. Mongo is app and running. I've tried so far, restarting the DB, with no good results.
Just tried to insert from mongo client and worked
> db.mysecretcollection.insert({url:"sampletestremoveme"});
WriteResult({ "nInserted" : 1 })
So it seems to be a Node.js / Mongoose issue.

It seems to me that the document was too big, actually I was able to save it after removing one of its fields. The weird thing is that mongoose should catch that with "Error: Document exceeds maximum allowed bson size of XXX bytes" exception, but that was never thrown.

Related

Testing with mongoose and typescript: RangeError: Maximum call stack size exceeded - node_modules/mongodb/src/bson.ts:38:3

I'm running tests with jest on a node/express application. Anytime that I run anything with mongoose I get the following error:
● Test suite failed to run
RangeError: Maximum call stack size exceeded
at Object.get [as ObjectId] (node_modules/mongodb/src/bson.ts:38:3)
at Object.get [as ObjectId] (node_modules/mongodb/src/bson.ts:38:3)
(... line repeats total of 10 times)
When I've read other stackoverflow posts on this it tends to be an issue of iterating over multiple documents, but I still get an issue when I'm considering a single document:
test("mongoose works", async () => {
console.log("this does not log") // Nothing logs and I get the "test suite failed to run" error
const findResponse = await UserAction.findOne({
action: "testString1",
}).exec();
expect(findResponse).toBe(false);
});
The fact that my console.log doesn't run at all makes me thing there's something wrong with mongoose/typescript. If I remove mongoose from the test it runs fine.
The problem appears to have been with my jest.config.js file. I had moduleDirectories: ["node_modules", "src"], set. When I commented this line out I no longer had the problem.

Line number error does not show up when using MSSQL Node?

I have been using MySQL database with Nodejs for a while. I recently switched to MSSQL with Nodejs
When using a try catch block with Nodejs and Mysql any error with the query execution would give me the line at which the error occured
So while using MySQL I did:
try{
await pool.quer(`sql statement`)
}
catch(err){
console.log(err)
}
This would give me an error and the line number of error. But with node-mssql, I get:
{ RequestError: Incorrect syntax near 'Invalid'.
at StreamEvents.req.once.err (C:\Users\David\Main Web\node_modules\mssql\lib\msnodesqlv8\request.js:463:17)
at Object.onceWrapper (events.js:277:13)
at StreamEvents.emit (events.js:189:13)
at errors.forEach.err (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:33:20)
at Array.forEach (<anonymous>)
at routeStatementError (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:26:14)
at invokeObject.end (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\reader.js:258:13)
at freeStatement (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\driver.js:160:13)
at cppDriver.freeStatement (C:\Users\David\Main Web\node_modules\msnodesqlv8\lib\driver.js:150:11)
code: 'EREQUEST',
originalError:
{ Error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'Invalid'. sqlstate: '42000', code: 102 },
name: 'RequestError',
number: 102,
state: undefined }
This is such an unhelpful error. I know where the error is coming from for this error because there is only one sql statement getting executed right now but as my program grows without knowing where the error is coming from it will be hard to debug. Is this an expected behavior of node-mssql?
If you see the documentation here, it clearly mentions what it return in error and what not.
It clearly mentions that "Those errors are initialized in node-mssql module and its original stack may be cropped. You can always access original error with err.originalError"
In your catch block you can try printing the stack trace. That should give you the line number where the error occurred. You can use one of the following statements:
console.stack("---TRACE---")
OR
var stackTrace = new Error().stack
console.log(stackTrace)

Syntax error when using sequelize postgres

sequelize: 1.7.0
pg: 2.11.1
posgreSql: 9.3 (pg server on my pc)
I have app that is using following config:
db: 'mysql://user:pass#localhost/dbname'
And it works with sequelize and mysql dialect.
When I change it to:
db: 'postgres://user:pass#localhost/dbname'
and dialect to postgres and try to sequelize.sync() I get following error:
{
"message":"syntax error at or near \"(\"",
"name":"error",
"stack":"error: syntax error at or near \"(\"\n at Connection.parseE (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:561:11)\n at Connection.parseMessage (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:390:17)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:92:20)\n at EventEmitter.emit (events.js:95:17)\n at Socket.<anonymous> (_stream_readable.js:746:14)\n at EventEmitter.emit (events.js:92:17)\n at emitReadable_ (_stream_readable.js:408:10)\n at emitReadable (_stream_readable.js:404:5)\n---------------------------------------------\n at module.exports.CustomEventEmitter.failure.CustomEventEmitter.fail.CustomEventEmitter.error (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:93:10)\n at exec (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:92:14)\n at onError (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:72:11)\n at EventEmitter.emit (events.js:95:17)\n at module.exports.CustomEventEmitter.emit (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:61:33)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:131:17)\n---------------------------------------------\n at module.exports.CustomEventEmitter.failure.CustomEventEmitter.fail.CustomEventEmitter.error (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:93:10)\n at exec (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:92:14)\n at onError (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:72:11)\n at EventEmitter.emit (events.js:95:17)\n at module.exports.CustomEventEmitter.emit (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:61:33)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:131:17)",
"code":"42601"
},
"msg":"uncaughtException",
"time":"2014-03-31T14:17:29.496Z",
"v":0
}
What I am doing wrong?
Before I created dbname database in pg there was error missing database so I guess sequelize is connected to pg but it generates some syntax errors in pgsql code??
the problem was that in model schema I had Sequelize.INTEGER(11) - and postgres does not allow to pass 11 as a size of INTEGER - this will be solved in 2.x.x version of Sequelize (You can find issue corresponding to this problem on sequelize github repo).
Sequelize and postgres work well for me. Did you set dialect, protocol, port correctly in config.js like this
{
"development":{
"username":"name",
"password":"pass",
"database":"db",
"dialect":"postgres",
"protocol":"postgres",
"host":"127.0.0.1",
"port":"5432"
},
...

Having problems running nodeBB with redis on windows7

I install redis on win7 by exe and I got nodeBB on
there are some first time config prompt and then
nodeBB even start populating database with default config.
After entering admin name email pwd, I got stuck here as below:
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\redis\in
dex.js:535 throw err; ^ TypeError: Object # has no method 'genSalt' at
Object.User.hashPassword
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\src\user.js:555:10) at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\src\user.js:13
3:11 at try_callback
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\
node_modules\redis\index.js:532:9) at RedisClient.return_reply
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\node_modules\redis\index.js:614:13) at ReplyParser.
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\Nod
eBB-master\node_modules\redis\index.js:266:14) at
ReplyParser.EventEmitter.emit (events.js:95:17) at
ReplyParser.send_reply
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\Node
BB-master\node_modules\redis\lib\parser\javascript.js:300:10) at
ReplyParser.execute
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-
master\node_modules\redis\lib\parser\javascript.js:189:22) at
RedisClient.on_data
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-
master\node_modules\redis\index.js:488:27) at Socket.
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-m
aster\node_modules\redis\index.js:82:14)
Then i change redis into mongo and i've got the similar error as below:
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\mongodb\
lib\mongodb\connection\base.js:242 throw message; ^ TypeError: Object#
has no method 'genSalt' at Object.User.hashPassword (c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\src\user.js:555:10) at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\src\user.js:13
3:11 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\src\database\m
ongo.js:418:5 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\collection\core.js:703:14 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\db.js:1098:5 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\db.js:1806:9 at Server.Base.callHandler
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\nodemodules\mongodb\lib\mongodb\connection\base.js:442:41)
at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\connection\server.js:485:18 at MongoReply.parseBody
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB
-master\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null. (c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-mas
ter\node_modules\mongodb\lib\mongodb\connection\server.js:443:20)

Reconnect MongoDB using MongoSkin ( Nodejs )

I have been using MongoSkin( Nodejs ) plugin to connect Mongodb as below.
var db = mongo.db(dbconfig.mongo_ip+'/'+dbconfig.mongo_db_name);
db.collection('myprofile').findOne({_id:memberid}, function(err, session){
if(err){
db.close();
console.log(err.stack);
}
})
If i got the mongo connection error from node.js, then how do i reconnect the same using mongoskin,
Mongo Connect errr: Error: failed to connect to [localhost:27017]
at [object Object].<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:184:51)
at [object Object].emit (events.js:45:17)
at [object Object].<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:110:14)
at [object Object].emit (events.js:45:17)
at Socket.<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection.js:301:10)
at Socket.emit (events.js:42:17)
at Array.33 (net.js:799:27)
at EventEmitter._tickCallback (node.js:108:26)
Please help me on this.
A good place to start is
https://github.com/kissjs/node-mongoskin/blob/master/test/db.js
but I assume you need to call open on db under mongoskin as well as in the driver.

Resources