I have a multi-page mean.js app, that I need to host. I've tried the steps in this guide https://scotch.io/tutorials/deploying-a-mean-app-to-amazon-ec2-part-2 but when I try to run a local version of my app using a remote version of mongodb on an amazon EC2 instance, I run into the following error.
C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:246
throw message;
^
Error: Error setting TTL index on collection : sessions
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\connect-mongo\lib\connect-mongo.js:169:23
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1499:46
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1632:20
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\command_cursor.js:152:16
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1196:16
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:1905:9
at Server.Base._callHandler (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:453:41)
at C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:488:18
at MongoReply.parseBody (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:446:20)
at emit (events.js:107:17)
at null.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_pool.js:207:13)
at emit (events.js:110:17)
at Socket.<anonymous> (C:\Users\Forest\Desktop\CS\BOROWR\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.js:440:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
In terms of my code, the only thing I've changed is replacing the line
module.exports = {
db: 'mongodb://localhost/borowr-dev',
with
module.exports = {
db: 'mongodb://MY_EC2_URL.com:27017/borowr-dev',
I previously tried updating my version of connect-mongo from 0.4.2 to 1.1.0, which caused other problems. Any help is appreciated, thanks.
Related
I'm trying to connect hyperledger-explorer to IBM Cloud Databases for Postgres instance. I provide the correct credentials to connect to DB. However, the app gives authentication errors.
[2021-08-19T10:38:01.088] [ERROR] PgService - error when connecting to db: error: no pg_hba.conf entry for host "172.30.229.241", user "ibm_cloud_a55353b8_7766_4dbb_9c6b_89ee7b666773", database "ibmclouddb", SSL off
at Connection.parseE (/opt/explorer/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/opt/explorer/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/opt/explorer/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
From inside the explorer pod, I installed psql -for investigation- and tried to connect to my instance using
PGPASSWORD=xxx psql 'host=xxx po
rt=xxx dbname=ibmclouddb user=ibm_cloud_user'
and it works, I was able to connect to the DB.
I'm sure the application uses incorrect connection strings to DB. But, I can't see what it sends to verify
any idea how can I resolve this?
I have been trying for a few days to connect my mongoDB to MEAN stack without success. Its running on AWS lightsail (Bitnami). The website itself is running fine, except for any pages that have an ajax/db call, as the database is not connecting/authenticating my connection string.
I am using the mongo,node, express part of the stack, I do not need or know any angular at present. I thought this would be easier than setting up on nodeJS and then adding mongoDB separately (well i did try that first with similar problems), I do intend to learn angualar in future so this is probably better long term. Server side set up is currently a weakness.
I am using mongoose for the connection. I can access the database using:
mongo admin --username root -p password via SSH.
I can also access the db via Rockmongo SSH. There is currently only one admin user in the database at present i.e. root.
My initial server/startup file is below:
server.js
const app = require('/opt/bitnami/apps/MYAPP/app.js');
require('dotenv').config({ path: 'variables.env' });
const mongoose = require("mongoose");
mongoose.Promise = global.Promise;
mongoose.connect(process.env.DATABASE_CONN);
app.listen(3000,function(){
console.log("Server has started!");
});
variables.env
DATABASE_CONN = mongodb://root:password#127.0.0.1:27017/MYAPPDATABASE
I have also tried many other connections strings, exchanging root for bitnami default user, etc.
When I go to my app folder and start the server (npm start or node server.js), the website starts up but with the below mongoDB authentication errors, below is only the first section.
> Server has started!
Connection error: { MongoError: Authentication failed.
at /opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/mongodb-core/lib/con
nection/pool.js:595:61
at authenticateStragglers (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modu
les/mongodb-core/lib/connection/pool.js:513:16)
at Connection.messageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_m
odules/mongodb-core/lib/connection/pool.js:549:5)
at emitMessageHandler (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
mongodb-core/lib/connection/connection.js:309:10)
at Socket.<anonymous> (/opt/bitnami/apps/MYAPP/node_modules/mongoose/node_modules/
mongodb-core/lib/connection/connection.js:452:17)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:597:20)
name: 'MongoError',
message: 'Authentication failed.',
ok: 0,
errmsg: 'Authentication failed.',
code: 18,
codeName: 'AuthenticationFailed' }
Any help or direction would be much appreciated. Thank you kindly.
Mos.
OK. Solution found.
In the mongo.conf file I set the dbpath to /data/db
The mongo shell is pointed to /opt/bitnami/mongodb/tmp/mongodb-27017.sock "$#"
go to /opt/bitnami/mongodb/bin/mongo
change /opt/bitnami/mongodb/tmp/mongodb-27017.sock "$#" to /tmp/mongodb-27017.sock "$#"
Can do that using sudo nano /opt/bitnami/mongodb/bin/mongo then edit the file.
Still have noauth turned on, so next step is getting my db connection string to authenticate.
Hope it helps someone.
Thanks
Some improvement. I have edited mongo.conf for now to enable no auth. I then ran mongod which stated no /data/db folder for which it stores data. So I created the folders and ran mongod again. Now all pages work but the mongo shell command 'mongo' will not work on the terminal.
I think its because the mongod dbpath is set to data/db and the mongodb conf file dbpath is set to /opt/bitnami/mongodb/data/db.
So I am trying to update the mongod dbpath but it doesnt seem to update.
I have set the necessary permissions on mongodb atlas.i am trying to write to a database test from node.js, this is code in my
products.js:
router.post('/:productId', (req ,res ,next) => {
const id = req.params.productId;
Product.findById(id)
.exec()
.then(doc=> {console.log(doc);
res.status(200).json(doc).catch(err => console.log(err))
})
.catch(err =>{ console.log(err);
res.status(500).json({error: err});
})
});
Terminal shows the error:
UnhandledPromiseRejectionWarning: MongoError: user is not allowed to do action [insert] on [test.products]
at C:\Users\Hiary\Documents\rest-api\node_modules\mongodb-core\lib\connection\pool.js:598:61
at authenticateStragglers (C:\Users\Hiary\Documents\rest-api\node_modules\mongodb-core\lib\connection\pool.js:516:16)
at Connection.messageHandler (C:\Users\Hiary\Documents\rest-api\node_modules\mongodb-core\lib\connection\pool.js:552:5)
at emitMessageHandler (C:\Users\Hiary\Documents\rest-api\node_modules\mongodb-core\lib\connection\connection.js:309:10)
at TLSSocket.<anonymous> (C:\Users\Hiary\Documents\rest-api\node_modules\mongodb-core\lib\connection\connection.js:452:17)
at TLSSocket.emit (events.js:180:13)
at addChunk (_stream_readable.js:274:12)
at readableAddChunk (_stream_readable.js:261:11)
at TLSSocket.Readable.push (_stream_readable.js:218:10)
at TLSWrap.onread (net.js:581:20)
(node:21692) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
I have given permissions as shown in below screenshot
This can happen if you have a user that only has permission to a certain database but you do not include this in your connection string. E.g. the connection string atlas will recommend is
mongodb+srv://:#productive.abcd.mongodb.net/?retryWrites=true&w=majority
but if your user only has access to the database "my-database" the connection string should look like this
mongodb+srv://:#productive.abcd.mongodb.net/my-database?retryWrites=true&w=majority
Mongodb Atlas doesn't seem to work with postman,or have some kind of problem with their setup,I now have my mondgodb hosted with mLab and everything works fine,didn't have to change my code
When Copying the connection string compatible with your driver version from mongodb.Atlas choose the first one, if it is not working choose the second.
Just add mongodb rules (readWriteAnyDatabase#Admin) in Database access..
just do it
This is related to migration to parse server from api.parse.com.
On windows server, installed mongo db and nodeJS.
Installed Python.
Installed Parse Server.
Getting following error messages.
StyleChat is the name of the app.
http://localhost:1337/stylechat
parse-server-example running on port 1337. info: Parse LiveQuery
Server starts running warn: Unable to ensure uniqueness for usernames:
Error: read ECONNRESET
at exports._errnoException (util.js:1036:11)
at TCP.onread (net.js:564:26) warn: Unable to ensure uniqueness for user email addresses: Error: read ECONNRESET
at exports._errnoException (util.js:1036:11)
at TCP.onread (net.js:564:26) (node:252160) UnhandledPromiseRejectionWarning: Unhandled promise rejection
(rejection id: 4): MongoError: read ECONNRESET (node:252160)
UnhandledPromiseRej
if you run nodejs on window, you should use iisnode to run nodejs on iis.
i found this here
have fun.
I have a meteor web app that connects to a mongohq database. It's working correctly on heroku, but I can't get it to work on my localhost. It was working on localhost yesterday, but not today.
To be certain, I just ran a git clone in a new folder. Even this clone is throwing errors on localhost. Here's my terminal (FYI, I'm on a windows 8.1 machine that is running an Ubuntu virtual box; also, I've removed the username / password from the log, below):
adam#adam-VirtualBox:~/resSingleTestV2/faze1tables$ export MONGO_URL=mongodb://<username>:<password>#oceanic.mongohq.com:10033/test_db
adam#adam-VirtualBox:~/resSingleTestV2/faze1tables$ meteor
[[[[[ ~/resSingleTestV2/faze1tables ]]]]]
=> Started proxy.
=> Started your app.
=> App running at: http://localhost:3000/
I20140511-12:53:43.438(-4)? Exception in callback of async function: Error: failed to connect to [oceanic.mongohq.com:10033]
I20140511-12:53:43.637(-4)? at null.<anonymous> (/home/adam/.meteor/packages/mongo-livedata/0120179b5c/npm/node_modules/mongodb/lib/mongodb/connection/server.js:536:74)
I20140511-12:53:43.640(-4)? at EventEmitter.emit (events.js:106:17)
I20140511-12:53:43.641(-4)? at null.<anonymous> (/home/adam/.meteor/packages/mongo-livedata/0120179b5c/npm/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:150:15)
I20140511-12:53:43.641(-4)? at EventEmitter.emit (events.js:98:17)
I20140511-12:53:43.643(-4)? at Socket.<anonymous> (/home/adam/.meteor/packages/mongo-livedata/0120179b5c/npm/node_modules/mongodb/lib/mongodb/connection/connection.js:516:10)
I20140511-12:53:43.643(-4)? at Socket.EventEmitter.emit (events.js:95:17)
I20140511-12:53:43.644(-4)? at net.js:440:14
I20140511-12:53:43.644(-4)? at process._tickCallback (node.js:415:13)
Any help appreciated. Thanks.
I'm connecting via my school's wifi. Turns out they must've done something to prevent me from connecting to mongoHQ because I'm able to connect via other networks.
Strange that it worked for a day or two and then stopped.