简体   繁体   中英

What should I enter to the connection string to connect my NodeJS application to a MongoDB server?

I am trying to connect to a MongoDB to a nodejs. I have the MongoDB running and I have an ENV file with a connection string variable. I just don't know what to set the string to connect the data I created to the data.

Terminal:

connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a301b4da-919f-4e58-a524-b6851fac71c7") }
MongoDB server version: 4.4.4
---
The server generated these startup warnings when booting: 
        2021-04-15T18:15:59.961-04:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
        2021-04-15T18:15:59.961-04:00: Soft rlimits too low
        2021-04-15T18:15:59.961-04:00:         currentValue: 256
        2021-04-15T18:15:59.961-04:00:         recommendedMinimum: 64000
---
---
        Enable MongoDB's free cloud-based monitoring service, which will then receive and display
        metrics about your deployment (disk utilization, CPU, operation statistics, etc).

        The monitoring data will be available on a MongoDB website with a unique URL accessible to you
        and anyone you share the URL with. MongoDB may use this information to make product
        improvements and to suggest MongoDB products and deployment options to you.

        To enable free monitoring, run the following command: db.enableFreeMonitoring()
        To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> 

.env

CONNECTION_STRING="mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb"

Remove gssapiServiceName & compressors from connection string and add DB name at the end like the example below

CONNECTION_STRING="mongodb://127.0.0.1:27017/db_name"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM