xxxxxxxxxx
$ wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | apt-key add -
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.2.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
$ sudo service mongod status
mongod start/running, process 3627
$ mongo --version
MongoDB shell version v4.2.8
git version: 43d25964249164d76d5e04dd6cf38f6111e21f5f
OpenSSL version: OpenSSL 1.1.1 11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1804
distarch: x86_64
target_arch: x86_64
$
$ pip3 install pymongo
$ python3
>>> import pymongo
>>> pymongo.__version__
'3.10.1'
xxxxxxxxxx
# You can easily install mongodb to run locally on your windows machine using chocolatey
# run
$ choco install mongodb
# to properly set up, add the mongodb path -- in my case it is; C:\Program Files\MongoDB\Server\5.3\bin -
# to your system environment variables
# then test your installation
$ mongo --version
# expected output
# MongoDB shell version vx.y.z
# Build Info: {
# "version": "x.y.z",
# "gitVersion": "ea201bb0ab5fa4c9c9d27c29a538987db15c0a36",
# "modules": [],
# "allocator": "tcmalloc",
# "environment": {
# "distmod": "windows",
# "distarch": "x86_64",
# "target_arch": "x86_64"
# }
#}
xxxxxxxxxx
# Step 1: Download MongoDB
# Visit the MongoDB website (https://www.mongodb.com/) and download the latest stable release for Windows.
# Step 2: Extract the MongoDB archive
# Extract the downloaded archive file (e.g., mongodb-winXX-version) to a desired location on your computer.
# Step 3: Configure MongoDB
# Create a new folder on your C:\ drive named 'data' and another folder within 'data' named 'db'. This is where MongoDB will store its data.
# Open a Command Prompt window as administrator and navigate to the 'bin' directory inside the extracted MongoDB folder.
# Step 4: Start MongoDB
# Run the following command to start the MongoDB instance:
mongod --dbpath C:\data\db
# Step 5: Connect to MongoDB
# Open another Command Prompt as administrator and navigate to the 'bin' directory inside the MongoDB folder.
# Run the following command to start the MongoDB shell:
mongo
xxxxxxxxxx
alias mongod="/c/Program\ files/MongoDB/Server/4.0/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongo.exe"
xxxxxxxxxx
openssl rand -base64 756 > /opt/mongo-keyfile chmod 400 /opt/mongo-keyfile chown mongodb:mongodb /opt/mongo-keyfile
xxxxxxxxxx
in <project-name>/app.js
var app = express();
/*....*/
//////mongoose
// Set up mongoose connection
var mongoose = require('mongoose');
var dev_db_url = 'mongodb+srv://<username>:<password>@cluster0.sekti.mongodb.net/example?retryWrites=true&w=majority';
var mongoDB = process.env.MONGODB_URI || dev_db_url;
const uri = process.env.MONGODB_URI;
mongoose.connect(mongoDB, {useNewUrlParser: true, useUnifiedTopology: true});
mongoose.Promise = global.Promise;
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
//////
///replace <username> and <password> with your actual username and password of course
xxxxxxxxxx
1. Download MongoDB from the official website: https://www.mongodb.com/try/download/community
2. Launch the installer and follow the wizard.
3. Select the Complete option for the setup type and click Next.
4. Choose the destination folder where MongoDB will be installed, or keep the default folder. Click Next.
5. Choose whether to install MongoDB as a service or not. Select "Run service as Network Service user" and check the "Install MongoDB Compass" option if desired. Click Next.
6. Configure the MongoDB instance by choosing the data directory and the MongoDB port. You can leave the defaults or modify them as needed. Click Next.
7. Choose whether to enable MongoDB's command-line options. Select the desired options or leave the default configuration. Click Next.
8. Review the installation summary and click Install to start the installation process.
9. Wait for the installation to complete.
10. Once the installation finishes, click Finish to exit the installer.
11. MongoDB is now installed on your Windows machine. You can open a Command Prompt or PowerShell window and use the `mongod` command to start the MongoDB server.