Sådan downloader og installerer du MongoDB on Windows og Cloud
⚡ Smart opsummering
Sådan downloades og installeres MongoDB on Windows and Cloud is explained as a complete setup guide. This resource covers installing MongoDB Community Server on Windows, Javamanuskript, Python, and Ruby drivers, MongoDB Compass, configuration with import and export, a config file, and deploying MongoDB Atlas on the cloud.

Installatørerne til MongoDB are available in both the 32-bit and 64-bit format. The 32-bit installers are good for development and test environments. But for production environments you should use the 64-bit installers. Otherwise, you can be limited in the amount of data that can be stored within MongoDB. It is advisable to always use the stable release for production environments.
Sådan downloader og installerer du MongoDB on Windows
Følgende trin kan bruges til at downloade og installere MongoDB on Windows 10:
Trin 1) Download MongoDB Community Server
Gå til link og downloade MongoDB Fællesskabsserver. Vi installerer 64-bit versionen til Windows.
Trin 2) Klik på Opsætning
Once the download is complete, open the msi file. Click Next in the start-up screen.
Trin 3) Accepter slutbrugerlicensaftalen
- Accept the End-User License Agreement.
- Klik på Næste.
Step 4) Click on the “Complete” button
Click on the “Complete” button to install all of the components. The custom option can be used to install selective components or if you want to change the location of the installation.
Trin 5) Servicekonfiguration
- Select “Run service as Network Service user”. Make a note of the data directory; we will need this later.
- Klik på Næste.
Trin 6) Start installationsprocessen
Klik på knappen Installer for at starte installationen.
Step 7) Click Next once completed
Installation begins. Click Next once completed.
Trin 8) Klik på knappen Udfør
Final step: once the installation is complete, click on the Finish button.
Hej Verden MongoDB: JavaScript-driver
Chauffører ind MongoDB are used for connectivity between client applications and the database. For example, if you had a Java programmet og krævede det at oprette forbindelse til MongoDB, then you would require to download and integrate the Java driver, så programmet kan arbejde med MongoDB databasen.
Driveren til JavaScript kommer ud af kassen. De MongoDB shell which is used to work with the MongoDB database is actually a JavaScript shell. To access it:
Trin 1) Go to “C:\Program Files\MongoDB\Server\4.0\bin" og dobbeltklik på mongo.exe. Alternativt kan du også klikke på MongoDB desktop item.
Trin 2) Enter the following program into the shell:
var myMessage='Hello World'; printjson(myMessage);
Code Forklaring:
- Vi erklærer blot en simpel JavaScript variable to store a string called ‘Hello World’.
- Vi bruger printjson-metoden til at udskrive variablen på skærmen.
Installer Python Chauffør
Trin 1) Sørg Python is installed on the system.
Trin 2) Install the mongo related drivers by issuing the below command:
pip install pymongo
Installer Ruby-driver
Trin 1) Ensure Ruby is installed on the system.
Trin 2) Ensure gems is updated by issuing the command:
gem update --system
Trin 3) Install the mongo related drivers by issuing the below command:
gem install mongo
Installer MongoDB Compass - MongoDB Ledelsesværktøj
Der er værktøjer på markedet, som er tilgængelige til styring MongoDB. Et sådant ikke-kommercielt værktøj er MongoDB Compass. Some of the features of Compass are given below:
- Full power of the Mongo shell
- Flere skaller
- Flere resultater
Trin 1) Gå til link and click download.
Trin 2) Enter details in the popup and click submit.
Trin 3) Double click on the downloaded file.
Trin 4) Installation will auto-start.
Trin 5) Compass will launch with a Welcome screen.
Trin 6) Keep the privacy settings as default and click “Start Using Compass”.
Trin 7) You will see the home screen with a list of current databases.
MongoDB Konfiguration, import og eksport
Før du starter MongoDB server, det første nøgleaspekt er at konfigurere databiblioteket, hvor alle MongoDB data will be stored. This can be done in the following way:
Ovenstående kommando 'md \data\db' laver en mappe kaldet \data\db på din nuværende placering. MongoDB vil automatisk oprette databaserne på denne placering, fordi dette er standardplaceringen for MongoDB at gemme sine oplysninger. Vi sikrer bare, at mappen er til stede, så det MongoDB kan finde den, når den starter.
Import af data til MongoDB gøres ved at bruge kommandoen "mongoimport". Følgende eksempel viser, hvordan dette kan gøres.
Trin 1) Create a CSV file called data.csv and put the following data in it:
Employeeid,EmployeeName 1,Guru99 2,Mohan 3,Smith
So in the above example, we are assuming we want to import 3 documents into a collection called data. The first row is called the header line, which will become the field names of the collection.
Trin 2) Issue the mongoimport command.
Code Forklaring:
- We are specifying the db option to say which database the data should be imported to.
- The type option is to specify that we are importing a csv file.
- Remember that the first row is called the header line, which will become the field names of the collection; that is why we specify the –headerline option. And then we specify our data.csv file.
Produktion
Outputtet viser tydeligt, at 3 dokumenter blev importeret til MongoDB.
Eksporterer MongoDB is done by using the mongoexport command.
Code Forklaring:
- Vi angiver db-muligheden for at sige, hvilken database dataene skal eksporteres fra.
- We are specifying the collection option to say which collection to use.
- The third option is to specify that we want to export to a csv file.
- Den fjerde er at angive, hvilke felter i samlingen der skal eksporteres.
- Indstillingen –out angiver navnet på den csv-fil, som dataene skal eksporteres til.
Produktion
Outputtet viser tydeligt, at 3 poster blev eksporteret fra MongoDB.
Konfiguration MongoDB server med konfigurationsfil
One can configure the mongod server instance to start up with a configuration file. The configuration file contains settings that are equivalent to the mongod command-line options. For example, suppose you wanted MongoDB to store all its logging information to a custom location, then follow the below steps:
Trin 1) Create a file called “mongod.conf” and store the below information in the file.
- The first line of the file specifies that we want to add configuration for the system log file, that is where the information about what the server is doing goes, in a custom log file.
- Den anden mulighed er at nævne, at placeringen vil være en fil.
- This mentions the location of the log file.
- LogAppend: "true" betyder at sikre, at logoplysningerne bliver ved med at blive tilføjet til logfilen. Hvis du angiver værdien som "false", vil filen blive slettet og oprettet på ny, hver gang serveren starter igen.
Trin 2) Start the mongod server process and specify the above created configuration file as a parameter. The screenshot of how this can be done is shown below.
Once the above command is executed, the server process will start using this configuration file, and if you go to the /etc directory on your system, you will see the mongod.log file created. The below snapshot shows an example of what a log file would look like.
Sådan installeres MongoDB i skyen (AWS, Google, Azure)
You do not need to install the MongoDB server and configure it. You can deploy a MongoDB Atlas server i skyen på platforme som AWS, Google Cloudog Azure, and connect to the instance using a client. Below are the detailed steps:
Trin 1) Gå til link.
- Indtast personlige oplysninger
- Accepter vilkårene
- Click the button “Get Started Free”
Trin 2) Click “Build my first cluster”.
Trin 3) Du kan vælge mellem AWS, Google Cloudog Azure as your cloud provider. In this tutorial, we will use AWS, which is set by default. Make no other changes on the page and click “Create Cluster".
Trin 4) Cluster creation takes some time.
Trin 5) After some time you will see the cluster ready.
Trin 6) Click Security > Add new user.
Trin 7) På det næste skærmbillede:
- Indtast brugerlegitimationsoplysninger
- Tildel privilegier
- Click the Add User button
Trin 8) In the dashboard, click the connect button.
- Whitelist din IP-forbindelse
- Vælg forbindelsesmetoden
Trin 9) Select the connection method of your choice to connect to the MongoDB serveren.


































