Skip to main content

Posts

Showing posts from June, 2021

Simple way to import and export collections in MongoDB

  A simple command will help to import and export collections in mongoDB. Export/Dump Collections in MongoDB: mongodump -d <database_name> -o <directory_backup> The above command will dump all the collections in the defined directory. eg: if your database name is awesome_db and you selected the my_db_backup as backup directory then you need run below command: mongodump -d awesome_db  -o my_db_backup If your db has authentication enabled then pass -u <username> -p <press enter> with the above command. Import/Restore Collection in MongoDB: mongorestore -d <database_name> <directory_backup> Similarly this command will restore the collections in the mongodb database.  for eg: mongodump -d awesome_db -o my_db_backup pass the authentication -u <username> -p <press enter> if your mongodb has authentiction. 

How to Setup Virtual Environment in Python with venv

A virtual environment is the most used tool by the developers to isolate the dependencies for different projects. Suppose you have two projects say porj1 and proj2 . proj1 needs the Django dependency with version 3.2 but your proj2 needs the Django dependency with version 2.2. In this situation you need a virtual environment to keep the both version on your system separately.  How to create virtual environment in python:  Decide a directory where you want to create the virtual environment. You can use your project directory or any other directory as per your wish.  Run the below command. Here` awesome_proj_env ` is the folder where virtual environment will be created. if the folder does not exists then it will be created automatically. python3 -m venv awesome_proj_env    Activate the virtual environment: On Linux/Mac OSX: source awesome_proj_env/bin/activate  On Windows: awesome_proj_env \Scripts\activate.bat Deactivate the virtual environment in Python: type " deactivate "