I'm trying to figure out why my MongoDB
connection is not connecting me to a particular database.
My connection string is mongodb://localhost:27017/
Meanwhile, I'm trying to execute the script somehow it appends database test
.
Here is my code from env.ts
:
const PRIMARY_DB_URI = process.env.PRIMARY_DB_URI || 'mongodb://localhost:27017/'
credentials: PRIMARY_DB_URI + '?socketTimeoutMS=360000&connectTimeoutMS=360000'
connection.ts:
export const fortisConnection = mongoose.createConnection(
database.credentials!
)
fortisConnection.on('connected', () => {
console.log(mongoose.connections)
})
I need to extract data from mongodb://localhost:27017/
but have such a log.
name: 'test',
host: 'localhost',
port: 27017,
user: undefined,
pass: undefined,
client: MongoClient {
_events: [Object: null prototype],
_eventsCount: 1,
_maxListeners: undefined,
s: [Object],
topology: [Server],
[Symbol(kCapture)]: false
},
Field name
states for database name
.
When I'm trying to connect to a particular database like: mongodb://localhost:27017/data
It does not connect to database data
and asks to return some users as shown below, it does not return anything.
script:
async function test() {
try {
const user = await User.find()
console.log(1, ' USER: ', user)
} catch(e) {
console.log(' error: ', e)
}
}
Question: why it appends test
to the database connection string?