mongoose connection to database failed error

I'm facing an issue when trying to connect to a database using mongoose.
The problem arises when I execute this code

var mongoose = require('mongoose').Mongoose;
var db = mongoose.connect('mongodb://localhost/goaljuice');

Upon running the above code, I encounter the following error message:

TypeError: Object function Mongoose() {
  this.connections = [];
  this.plugins = [];
  this.models = {};
  this.modelSchemas = {};
  this.options = {};
  this.createConnection(); // default connection
} has no method 'connect'
==================================

Here is the folder structure of my project:

-express_example
--app.js
--node_modules
------express, jade, mongodb, mongooses, stylus
--public
--router
--views

Answer №1

Opt for

let database = require('mongoose').Mongoose;

consider

let database = require('mongoose');

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

Tips for uploading files in filepicker with protractor

https://i.sstatic.net/noq46.png Here's a snippet of HTML code you might find useful: <input type="file" class="fileUploadInput" name="fileUpload" id="fileUploadInput" accept="application/msword,application/pdf,text/plain,application/rtf,applicat ...

Effortless data retrieval using JavaScript and PHP for JSON content

I have been on the lookout for a solution to implement lazy loading of JSON data from an API, especially since I am making multiple API calls per page. My search led me to discover this helpful resource: https://github.com/rpnzl/jquery-lazyjson/tree/v1.0 ...

Dependencies for Grunt tasks

I am facing some issues with a grunt task named taskA that was installed via npm. The task has a dependency on grunt-contrib-stylus, which is specified in the package.json file of taskA and installed successfully. However, when I run grunt default from the ...

Setting the default value for a dropdown in Angular 2 using Kendo UI

I'm currently facing an issue with creating a dropdownlist using Kendo UI. The problem arises when I try to set a default selected value upon loading the screen. Referring to their documentation, my code is structured like this: HTML: <kendo-drop ...

Assign the filename to the corresponding label upon file upload

I've customized my file uploader input field by hiding it and using a styled label as the clickable element for uploading files. You can check out the implementation on this jsFiddle. To update the label text with the actual filename once a file is s ...

Attempting to run a pair of JavaScript files simultaneously using the window.onload event

I'm facing an issue where two JavaScript files linked to a single HTML document are conflicting with each other. It seems like the second JS file is always taking precedence over the first one. I suspect that this might be related to both files using ...

Steps for importing an external .js file into a Vue 2 component

Hello, I am currently working on vue.js 2 and I have come across a problem with the JavaScript part. I would like to include the general.js file in my posts.vue file. Can anyone provide assistance with this? Your help would be greatly appreciated :) Below ...

The relevance of this concept in the classroom setting and within the setTimeout function is integral to

Having recently started learning JS, I have gone through various answers on the context of "this" with classes and setTimeout(), but I am facing a specific issue. I am struggling to understand the thought process or mental model behind the following code ...

Adjusting the height of the Iframe dynamically every 2 seconds

One issue I am facing is with the iframe height. When I load the iframe, it sets the height correctly and adjusts when content is loaded dynamically. However, if I reduce or delete content from the loaded page, the iframe height does not decrease (e.g., in ...

The jQuery timer I implemented is not showing up properly on my webpage

Here's a look at my HTML: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/boot ...

Is there a way to implement a setTimeout delay in my puppeteer browser?

I wrote a function named waitForTimeout to introduce a brief delay that can be awaited once the browser navigates to a new page. function waitForTimeout(timeout) { return new Promise((resolve) => { setTimeout(resolve, timeout) }) } const puppet = () =& ...

Is there someone who can assist me in transforming this constructor function into a factory function using Javascript?

const createAppError = (message, status) => { return { message, status }; }; This is the equivalent code using factory functions to create an AppError with a message and status. It achieves the same result as the constructor fun ...

"Firebase offers the flexibility to have several 'apps' configured, both on the client side and the server

Currently, I have a firebase app set up in my project for SSR using firebase-admin. However, I now want to add firebase@8 to be able to utilize it on the client-side and eventually apply firestore rules. The issue arises when I try to use firebase@8, I enc ...

Node-fetch enables dynamic requests

Seeking to retrieve real-time data from a fast-updating API has posed a challenge for me. The issue lies in my code constantly returning the same value. I've experimented with two approaches: var fetch = require("node-fetch"); for(let i=0; i<5; i+ ...

Identical code exhibiting varying behavior between localhost:3000 and the production server at localhost:5000 on the web

I'm currently in the process of learning React Js, but I've been encountering a persistent error that has me stumped. A specific component functions perfectly when running on my local server (localhost:3000), but as soon as I try to deploy it to ...

Express middleware often disregards the `next(new Error())` function call, allowing the code to proceed

When using the next(new Error()) method in my express middleware, I encountered an issue. Express is expected to redirect the code to the error handling middleware, which it does eventually, but only after completing the first middleware function entirely. ...

The JSONP request connected to the user input field and button will only trigger a single time

Hello all, I'm new to this and have been searching the internet high and low to see if anyone has encountered a similar issue before, but haven't had any luck. I've been attempting to set up a JSONP request to Wikipedia that is connected to ...

Is it possible for a client to "await" a stream coming from a server?

I currently have a basic node.js server setup with the main purpose of serving a single .txt file to simulate an API. To prevent overwhelming my RAM with large files, I am using streams to send the file in chunks to the client. server.on('request&apo ...

Best method for retrieving information from a string

Exploring different techniques to extract data from a string is a common practice, including methods like substring and split. Is there an optimal approach to accomplish this task? For instance, when faced with a URL structure such as http://myServer:8000/ ...

The function is not triggered when the select tag is changed

I'm currently working on implementing a drop-down menu using the <select> element in HTML. Here is the code snippet I have so far: <select id="Parameter1" onchange="function1()"> <option value = "0105" name = "Frequency">Frequency ...