September 10, 2024

MongoDB Debian howto

MongoDB is a NoSQL (which doesn’t mean No SQL, but Not Only SQL, which is sort of what big data is usually referred to as) that’s more popular these days. You can set it up from standard Debian repositories, or get the latest version using git clone, but here we’re showing standard Debian repositories:

apt install mongodb-server
mongod --version
  db version v3.2.11
  git version: 009580ad490190ba33d1c6253ebd8d91808923e4
  OpenSSL version: OpenSSL 1.0.2r  26 Feb 2019
  allocator: tcmalloc
  modules: none
  build environment:
    distarch: x86_64
    target_arch: x86_64

That means you installed it. Now login like and test it like:

mongo
  MongoDB shell version: 3.2.11
  connecting to: test
  Welcome to the MongoDB shell.
  For interactive help, type "help".
> use mydb;
switched to db mydb
> db.test.save ( { tecadmin: 100 } )
WriteResult({ "nInserted" : 1 })
> db.test.find()
{ "_id" : ObjectId("5d0bd638ab96ada73b406400"), "tecadmin" : 100 }

Now you need to create a database and test that. You don’t create like a normal mysql or some such, you run a command within mongodb, first let’s list the databases you already have:

> show dbs
local  0.000GB
mydb   0.000GB

Now to create a new database you just issue the ‘use’ command and it will be created, but only after you stick something in it:

> use newdatabase;
  switched to db newdatabase
> s = { Name : "somename" }
  { "Name" : "somename" }
> db.testData.insert( s );
  WriteResult({ "nInserted" : 1 })
> show dbs;
  local        0.000GB
  mydb         0.000GB
  newdatabase  0.000GB