Nodejs having trouble establishing a connection with mongodb

After attempting the code below to set up a new database, I can't seem to find it in my MongoDB local connection. Despite using a callback function that didn't return any errors.

const mongoose = require("mongoose");

mongoose.connect("mongodb://localhost:27017/personDB", { useUnifiedTopology: true, useNewUrlParser: true });

Answer №1

It appears there may be an error in your question already. I believe this should suffice. Make sure to verify that mongodb is operating correctly.

Give this a try

const mongoose = require('mongoose')

mongoose.connect(process.env.DATABASE, {
    useUnifiedTopology: true,
    useNewUrlParser: true
})

mongoose.connection.once('open', () => {
    console.log("Connection established")
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can you explain the sequence of steps involved in setting up a server in node.js?

I'm curious about the order in which instructions are executed in this code. Specifically, I want to know if http.createServer() or server.listen is executed first, and when the callback function inside createserver will execute. const http = require( ...

Wait for Protractor until the page has completely finished loading

After navigating to https://docs.angularjs.org/tutorial, I attempted to click on '0 - Bootstrapping' under Tutorial but Protractor did not wait for the page to fully load, resulting in an Error. Error: Failed to execute 'click' on &a ...

What is the best way to add two strings with indexes and points to a Three.js BufferGeometry?

I have a massive database containing tens of thousands of objects with various types of information, including their 3D meshes. Currently, I am attempting to display these objects in web browsers using Three.js. The object information is provided by anoth ...

What are the advantages of going the extra mile to ensure cross-browser compatibility?

It's fascinating how much effort is required to ensure web applications work seamlessly across all browsers. Despite global standards like those set by W3C, the development and testing process can be quite laborious. I'm curious why all browsers ...

Refresh the three.js Raycaster when the window size changes

Currently, I am implementing a ray caster to choose objects within my three.js scene. The specific objects I am working with are box geometries shaped like flooring. After a successful selection of an object, I encountered an issue where resizing the wind ...

Break down and extract the fully organized variable using a single expression

Is it possible to destructure a variable while still having access to the structured variable within the same function call? For instance, what can be used in place of ??? below to achieve the desired result (and what other changes might need to be made i ...

Incorporating JQuery Plugins into Angular 4 Apps

I am currently attempting to incorporate various jquery plugins, such as Magnific-Popup, into my Angular 4 application but encountering difficulties. I successfully installed jQuery using npm install --save-dev @types/jquery in the terminal, yet implementi ...

Utilizing jQuery and Bootstrap imports within a JavaScript file

Having difficulty importing libraries into my JS file. While the code functions when placed in a script tag in my HTML file (where I included jQuery and Bootstrap), it fails to work when placed in my JS file. My attempt to import the Bootstrap library thr ...

I'm curious about the distinction between React's one-way data binding and Angular's two-way data binding. Can someone please clarify the key differences

My understanding of these concepts is a bit hazy. If I were to develop the same ToDo application using AngularJS and ReactJS, what exactly distinguishes React ToDo's use of one-way data binding from AngularJS's two-way data binding? From what I ...

The functionality of the OnClientClick event within the ASP.NET platform

While utilizing ASP.NET to pass a value to a JavaScript function, I encountered an issue where it doesn't seem to work when trying to pass a value from another control. It seems to behave as if there is a syntax error and just reverts back to the main ...

Sequelize Authentication is unable to finalize

As I delve into the world of node.js and sequelize, I am encountering a persistent error: /home/cbaket/test/test.js:9 .complete(function(err) { ^ TypeError: undefined is not a function at Object.<anonymous> (/home/cbaket/test/test.js:9: ...

Storing and showcasing user submissions for a lasting viewing experience

I recently started learning Javascript and I am currently working on creating a web application that allows users to input details about fish species. I want this information to be stored permanently so that future users can access it. Is there a way to ...

tips on customizing buttons within form groups

I have set up two separate form-groups: My goal is to click on each button within each group and toggle its style from grey to green, and vice versa. However, when I click on a button, all buttons within the group turn grey except for the one that was cli ...

How can I create a fading trail effect in Three.js that diminishes over time?

I am interested in achieving a similar effect to the example I found on this website: However, my goal is to have the old trail gradually fade into the background over time instead of cluttering the screen with persistent marks. I discovered that by usin ...

Refresh the webpage content by making multiple Ajax requests that rely on the responses from the previous requests

I am facing a challenge where I need to dynamically update the content of a webpage with data fetched from external PHP scripts in a specific sequence. The webpage contains multiple divs where I intend to display data retrieved through a PHP script called ...

What is the best way to use JavaScript to insert HTML values and then display the final output?

Currently, I am using JavaScript to perform simple multiplication and addition operations, with the result being outputted into an HTML Element on a webpage. Strangely, instead of getting a sum value as the output, it seems like a combination of two values ...

Javascript class for creating random quotes

I am utilizing the JavaScript fetch API to display a random quote. The quote changes upon page load, however, I encounter a type error when clicking on the new quote button. Error message: TypeError: Cannot read properties of undefined (reading 'len ...

Is it possible to utilize react for constructing a static HTML, CSS, and JavaScript document?

As a front end content developer, my main focus is on creating content assets. I typically use vscode to build my html, css, and js files, and then upload these static files to the content management system. However, this approach doesn't give me the ...

Incorporating an NPM JavaScript library into Laravel version 8

I've integrated the mobiscroll javascript component library into my new Laravel 8 app by adding the minified css/js files to the public/css and public/js directories. However, I'd like to find a more seamless way to include these components by us ...

Implement varying styles in React components

In my React project, I am attempting to create a unique progress bar with custom styling. Specifically, I have a dynamically calculated percentage that I want to assign as the width of a div element. Initially, I tried achieving this using Tailwind CSS: &l ...