The MongoDB Core driver is the low level part of the 2.0 or higher MongoDB driver and is meant for library developers not end users. It does not contain any abstractions or helpers outside of the basic management of MongoDB topology connections, CRUD operations and authentication.
Think you’ve found a bug? Want to see a new feature in node-mongodb-native? Please open a case in our issue management tool, JIRA:
Bug reports in JIRA for all driver projects (i.e. NODE, PYTHON, CSHARP, JAVA) and the Core Server (i.e. SERVER) project are public.
The quick start guide will show you how to set up a simple application using Core driver and MongoDB. It scope is only how to set up the driver and perform the simple crud operations. For more inn depth coverage we encourage reading the tutorials.
Let's create a directory where our application will live. In our case we will put this under our projects directory.
mkdir myproject cd myproject
Create a package.json using your favorite text editor and fill it in.
Save the file and return to the shell or command prompt and use NPM to install all the dependencies.
You should see NPM download a lot of files. Once it's done you'll find all the downloaded packages under the node_modules directory.
Let's boot up a MongoDB server instance. Download the right MongoDB version from MongoDB, open a new shell or command line and ensure the mongod command is in the shell or command line path. Now let's create a database directory (in our case under /data).
mongod --dbpath=/data --port 27017
You should see the mongod process start up and print some status information.
Let's create a new app.js file that we will use to show the basic CRUD operations using the MongoDB driver.
First let's add code to connect to the server. Notice that there is no concept of a database here and we use the topology directly to perform the connection.
var Server = Serverassert = ;// Set up server connectionvar server =host: 'localhost'port: 27017reconnect: truereconnectInterval: 50;// Add event listenersserver;server;server;// Start connectionserver;
To connect to a replicaset we would use the
ReplSet class and for a set of Mongos proxies we use the
Mongos class. Each topology class offer the same CRUD operations and you operate on the topology directly. Let's look at an example exercising all the different available CRUD operations.
var Server = Serverassert = ;// Set up server connectionvar server =host: 'localhost'port: 27017reconnect: truereconnectInterval: 50;// Add event listenersserver
The core driver does not contain any helpers or abstractions only the core crud operations. These consist of the following commands.
insert, Insert takes an array of 1 or more documents to be inserted against the topology and allows you to specify a write concern and if you wish to execute the inserts in order or out of order.
update, Update takes an array of 1 or more update commands to be executed against the server topology and also allows you to specify a write concern and if you wish to execute the updates in order or out of order.
remove, Remove takes an array of 1 or more remove commands to be executed against the server topology and also allows you to specify a write concern and if you wish to execute the removes in order or out of order.
cursor, Returns you a cursor for either the 'virtual'
findcommand, a command that returns a cursor id or a plain cursor id. Read the cursor tutorial for more inn depth coverage.
command, Executes a command against MongoDB and returns the result.
auth, Authenticates the current topology using a supported authentication scheme.
The Core Driver is a building block for library builders and is not meant for usage by end users as it lacks a lot of features the end user might need such as automatic buffering of operations when a primary is changing in a replicaset or the db and collections abstraction.
The next step is to get more in depth information about how the different aspects of the core driver works and how to leverage them to extend the functionality of the cursors. Please view the tutorials for more detailed information.