Question

MongoDB and Mongoose Question I have a database-initializer.js file that initializes a MongoDB database. In it...

MongoDB and Mongoose Question

I have a database-initializer.js file that initializes a MongoDB database. In it is this line let db = client.db('myDatabase');

I want to have another file which is my server.js file (that uses Node.js and express to create a server and handle requests) and in that file I want to use mongoose and connect to the database initialized by the database-initializer.js file, would I do this by the following line:

var dbURL = 'mongodb://localhost:27017/myDatabase';

mongoose.connect(dbURL);

Would that be the name of the database I create? Would it work as intended?

Or would the URL have to be:

var dbURL = 'mongodb://localhost/myDatabase';

Thank you, I am a little confused.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

if you are using mongoose to connect to the data base

mongoose.connect('mongodb://localhost:27017/myDatabase', {useNewUrlParser: true});

where,

localhost - if you are running mongodb on the same machine, if mongodb is in different machine use the pulic ip of that machine(like 192.168.10.10)

27017 - is the default port that mongodb runs on a machine, it can be changed though(if you have changed use the changed port instead of 27017, else leave it as it is...)

myDatabase - is your database name, you can put any name that you wanted as your data base name here, and there is no need for that database to be already created, mongodb will create automatically for you if it is not created, if the database exist with that name, it will use that database without creating a new one.

Add a comment
Know the answer?
Add Answer to:
MongoDB and Mongoose Question I have a database-initializer.js file that initializes a MongoDB database. In it...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I would like to know how to utilize mongodb database. I have the software I even...

    I would like to know how to utilize mongodb database. I have the software I even created a database but I have no idea how to use it in my application to build a banking online website. I will be using the database just to store clients information and bank account numbers. see my last question if possible

  • Python Question. I am trying to connect to a database and create a table using Python...

    Python Question. I am trying to connect to a database and create a table using Python in this code but I keep getting an error on line 48 saying that "Quotes" is not defined. Could anyone please help me set this up correctly? I am using Azure SQL Database to create this. import pyodbc import json import requests as r import pprint connection_string = 'Driver={ODBC Driver 17 for SQL Server};' \ 'Server=randomquotegenerator.database.windows.net,1433;' \ 'Database=RandomQuoteGenerator;' \ 'Uid=carterholliday;' \ 'Pwd=MIS54002k19;' \ 'TrustServerCertificate=no;'...

  • Project Description In this project, you will be developing a multithreaded Web server and a simple...

    Project Description In this project, you will be developing a multithreaded Web server and a simple web client. The Web server and Web client communicate using a text-based protocol called HTTP (Hypertext Transfer Protocol). Requirements for the Web server The server is able to handle multiple requests concurrently. This means the implementation is multithreaded. In the main thread, the server listens to a specified port, e.g., 8080. Upon receiving an HTTP request, the server sets up a TCP connection to...

  • Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If...

    Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If you could start the assignment and tell me how to do the rest it would be greatly appreciated! (Quick thumbs up answer response if thorough and correct) Maintain automobile records in a database Write a shell script to create, view and modify a simple database that contains automobile records. The shell script has to be done in Bourne shell syntax (bash as a matter...

  • i need help with this python assignment asking for creating a simple database (client application )...

    i need help with this python assignment asking for creating a simple database (client application ) そ归乔 Assignment rh ENCS-393-2174-WW: Tset5.pdf A2.pdf textbook.pdf Department of ComputV ← → O仚 file:///C 18/comp%20348/A2.pdf 5. Print Report: This will print the contents of the database, sorted by name. Note that the sorted contents should be sent by the server back to the client and then displayed by the client app. The Print Report function is r because it is the primary way for...

  • Background: I have an Access-software (~30 simultaneous users) with split front- & back-end, both UI &...

    Background: I have an Access-software (~30 simultaneous users) with split front- & back-end, both UI & DB running on Access-files. Most important features for me are reports & printing, with emphasis on fast development and deployment to the users (updates 1-3 times per week, using as little time as possible). The environment is Win7 + Access 2010. Updates are handled with .BAT-batch file. The database might be upgraded into SQL Server Express or something later this year. Problems: The Access...

  • Part I – Build a simple Servlet called MyServlet using NetBeans. Add this Servlet to you...

    Part I – Build a simple Servlet called MyServlet using NetBeans. Add this Servlet to you “ChattBank” Project. This MyServlet will display a message like “Go Braves” in a simple <h1> tag. Run this servlet from a Browser window by typing in the servlet name in the URL line. (ie. http://localhost:8080/ChattBank/MyServlet). Make sure that your Server is up and running before you test this Servlet. The best way to do this is just Run your “ChattBank” Project once before you...

  • Answer the following and explain so I can double check my answers If you use the Management Studio to create a database, the Studio will automatically create a database file plus a ________________...

    Answer the following and explain so I can double check my answers If you use the Management Studio to create a database, the Studio will automatically create a database file plus a ______________________ file. 10 points    QUESTION 2 When you use the Management Studio to create a check constraint, you can specify whether you want the constraint enforced for insert or __________________ operations. 10 points    QUESTION 3 When you use the Management Studio to create a database, including its tables...

  • For Jupyter Notebook we have opened up a file using pandas but I am confused on...

    For Jupyter Notebook we have opened up a file using pandas but I am confused on this question and how to do it. Create a new dataframe that only contains the data where fuel is “regular” AND MPG is over 21. Call it Auto_sub. Label each section using markup to state what you are doing and what you see

  • I am reading a text file and trying to store the information into an array so...

    I am reading a text file and trying to store the information into an array so I can use this in different parts of my program. So a dynamic array. So far I have been able to retrieve the information from the text file and organize it by category (User name,User ID, User password) I am having troubles allocating an array and storing the information correctly. Since I have different data types (int, string) do I need to create a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT