Sunday, December 29, 2019

Running MongoDB on ChromeOS (via Crostini)

In my previous post I explored Linux application support in ChromeOS and Chromebooks (a.k.a. Crostini). Of course I was bound to try running MongoDB in this environment, which I found to work really well (for development purposes). Here's my notes on running a MongoDB database and tools on a Chromebook with Linux (beta) enabled:
  • In ChromeOS, launch the Terminal app (which opens a Shell inside the 'Penguin' Linux container inside the 'Termina' Linux VM)
  • Run the following commands which are documented in the MongoDB Manual page on installing MongoDB Enterprise on Debian (following the manual's tab instructions titled “Debian 9 "Stretch”):
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb http://repo.mongodb.com/apt/debian stretch/mongodb-enterprise/4.2 main" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list
sudo apt-get update
sudo apt-get install -y mongodb-enterprise
  • Start a MongoDB database instance running:
mkdir ~/data
mongod --dbpath ~/data
  • Launch a second Terminal window and then run the Mongo Shell against this database and perform a quick database insert and query test:
mongo
db.mycoll.insert({a:1})
db.mycoll.find()
db.mycoll.drop()
exit

  • Install Python 3 and the PIP Python package manager (using Anaconda) and then install the MongoDB Python driver (PyMongo):
wget https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh
bash Anaconda3-*-Linux-x86_64.sh
source ~/.bashrc
python --version
pip --version
pip install --user pymongo
  • Test PyMongo by running a small ‘payments data generator’ Python script pulled down from a GitHub repository (this should insert records into the MongoDB local database’s “fs.payments” collection; after letting it run for a minute, continuously inserting new records, press Ctrl-C to stop it):
git clone https://github.com/pkdone/PaymentsWriteReadConcerns.git
cd PaymentsWriteReadConcerns/
./payments-records-loader.py -p 1
  • Download MongoDB Compass (use the Ubuntu 64-bit 14.04+ version), install and run it against the 'localhost' MongoDB database and inspect the contents of the “fs.payments” collection:
wget https://downloads.mongodb.com/compass/mongodb-compass_1.20.4_amd64.deb
sudo apt install ./mongodb-compass_*_amd64.deb
mongodb-compass




Song for today: Sun. Tears. Red by Jambinai

1 comment:

Paul Done said...

Just tested on latest version of ChromeOS & Linux it bundles at of 31-Oct-2020. This version now uses Debian 10 (Buster).

As a result, the changes to installation are:

* Follow this for installing MongoDB: https://docs.mongodb.com/manual/tutorial/install-mongodb-enterprise-on-debian/ (choose Debian 10 "Buster" tab)
* Python3 is already installed, to see version run: $ python3 --version
* To install pip run: $ sudo apt install python3-pip
* To see pip version run: $ pip3 --version
* To install PyMongo run: $ pip3 install --user pymongo