Should I learn the MongoDB shell commands first or my language specific drivers?
Why so many online tutorials only teach the MongoDB shell?
Most tutorials and classes online will teach the MongoDB shell because it is universal to anybody using MongoDB. Wherever you are running the MongoDB shell, the syntax is the same no matter what environment you are running it on. So whether you intend to interact with MongoDB through NodeJS, PHP, Python, C++, or Ruby, the shell is common ground because it comes built into MongoDB wherever you install it or however you intend to interact with it.
How do I use MongoDB for my programming language?
You can click on the link and download the driver for your programming language and it will provide you detailed instructions on how to install the driver, typically via a package manager like npm (NodeJS), pip (Python), or gem (Ruby).
Once you have the driver installed you can start interacting with MongoDB by importing the driver and using the functions it provides
For a quick example here’s how you’d start using the driver for NodeJS:
npm install mongod --save
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const url = 'mongodb://localhost:27017';
// Database Name
const dbName = 'myproject';
// Create a new MongoClient
const client = new MongoClient(url);
// Use connect method to connect to the Server
console.log("Connected successfully to server");
const db = client.db(dbName);
Why they teach the shell?
So should I learn the MongoDB shell commands or learn my language specific syntax?
We highly recommend starting to interacting with MongoDB through one of the drivers. You quickly get your feet wet and closer to the finish line quicker. The syntax from the shell to the driver functions does not change much and it shouldn’t be a hard adjustment if you have to ever have to switch back to the shell or another programming language.
When things go wrong though knowing the shell is invaluable. So if you have time to get acquainted with connecting and interacting with MongoDB through the shell, we recommend it.
Pilot the ObjectRocket Platform Free!
Try Fully-Managed CockroachDB, Elasticsearch, MongoDB, PostgreSQL (Beta) or Redis.Get Started