• This repository has been archived on 04/Feb/2022
  • Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MongoDB core driver functionality aims to make the "smallest" viable driver api

Note: This package has been merged into the mongodb package, and is no longer being maintained as a standalone package

Build Status Coverage Status

Description

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.

MongoDB Node.JS Core Driver

what where
documentation http://mongodb.github.io/node-mongodb-native/
apidoc http://mongodb.github.io/node-mongodb-native/
source https://github.com/mongodb-js/mongodb-core
mongodb http://www.mongodb.org/

Blogs of Engineers involved in the driver

Bugs / Feature Requests

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.

Questions and Bug Reports

Change Log

http://jira.mongodb.org/browse/NODE

QuickStart

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.

Create the package.json file

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.

{
  "name": "myproject",
  "version": "1.0.0",
  "description": "My first project",
  "main": "index.js",
  "repository": {
    "type": "git",
    "url": "git://github.com/christkv/myfirstproject.git"
  },
  "dependencies": {
    "mongodb-core": "~1.0"
  },
  "author": "Christian Kvalheim",
  "license": "Apache 2.0",
  "bugs": {
    "url": "https://github.com/christkv/myfirstproject/issues"
  },
  "homepage": "https://github.com/christkv/myfirstproject"
}

Save the file and return to the shell or command prompt and use NPM to install all the dependencies.

npm install

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.

Booting up a MongoDB Server

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.

Connecting to MongoDB

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 = require('mongodb-core').Server
  , assert = require('assert');

// Set up server connection
var server = new Server({
    host: 'localhost'
  , port: 27017
  , reconnect: true
  , reconnectInterval: 50
});

// Add event listeners
server.on('connect', function(_server) {
  console.log('connected');
  test.done();
});

server.on('close', function() {
  console.log('closed');
});

server.on('reconnect', function() {
  console.log('reconnect');
});

// Start connection
server.connect();

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 = require('mongodb-core').Server
  , assert = require('assert');

// Set up server connection
var server = new Server({
    host: 'localhost'
  , port: 27017
  , reconnect: true
  , reconnectInterval: 50
});

// Add event listeners
server.on('connect', function(_server) {
  console.log('connected');

  // Execute the ismaster command
  _server.command('system.$cmd', {ismaster: true}, function(err, result) {

    // Perform a document insert
    _server.insert('myproject.inserts1', [{a:1}, {a:2}], {
      writeConcern: {w:1}, ordered:true
    }, function(err, results) {
      assert.equal(null, err);
      assert.equal(2, results.result.n);      

      // Perform a document update
      _server.update('myproject.inserts1', [{
        q: {a: 1}, u: {'$set': {b:1}}
      }], {
        writeConcern: {w:1}, ordered:true
      }, function(err, results) {
        assert.equal(null, err);
        assert.equal(1, results.result.n);

        // Remove a document
        _server.remove('myproject.inserts1', [{
          q: {a: 1}, limit: 1
        }], {
          writeConcern: {w:1}, ordered:true
        }, function(err, results) {
          assert.equal(null, err);
          assert.equal(1, results.result.n);

          // Get a document
          var cursor = _server.cursor('integration_tests.inserts_example4', {
              find: 'integration_tests.example4'
            , query: {a:1}
          });

          // Get the first document
          cursor.next(function(err, doc) {
            assert.equal(null, err);
            assert.equal(2, doc.a);

            // Execute the ismaster command
            _server.command("system.$cmd"
              , {ismaster: true}, function(err, result) {
                assert.equal(null, err)
                _server.destroy();              
            });
          });
      });
    });

    test.done();
  });
});

server.on('close', function() {
  console.log('closed');
});

server.on('reconnect', function() {
  console.log('reconnect');
});

// Start connection
server.connect();

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' find command, 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.

Next steps

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.

More Repositories

1

compass

The GUI for MongoDB.
TypeScript
913
star
2

boxednode

๐Ÿ“ฆ boxednode โ€“ Ship a JS file with Node.js in a box
TypeScript
603
star
3

mongosh

The MongoDB Shell
TypeScript
323
star
4

vscode

Connect to MongoDB and Atlas and directly from your VS Code environment, navigate your databases and collections, inspect your schema and use playgrounds to prototype queries and aggregations.
TypeScript
318
star
5

mongoose-autopopulate

Always populate() certain fields in your mongoose schemas
JavaScript
211
star
6

electron-squirrel-startup

Default Squirrel.Windows event handler for your Electron apps.
JavaScript
204
star
7

connect-mongodb-session

Lightweight MongoDB-backed session store for Connect and Express
JavaScript
169
star
8

kerberos

Kerberos library for node.js
C++
169
star
9

mongodb-schema

Infer a probabilistic schema for a MongoDB collection.
TypeScript
122
star
10

runner

Start all mongodb deployment types for testing
JavaScript
89
star
11

mongodb-prebuilt

Install MongoDB prebuilt package using npm https://npmjs.org/package/mongodb-prebuilt
TypeScript
57
star
12

bson-transpilers

Metatranspiler for the export to language / language modes Compass feature.
JavaScript
52
star
13

version-manager

Cross-platform helper for managing multiple versions of MongoDB
JavaScript
46
star
14

zstd

A Zstd Compression Library
JavaScript
44
star
15

bson-ext

The C++ bson parser for the node.js mongodb driver.
JavaScript
43
star
16

mongodb-topology-manager

Localhost MongoDB Topology Management API
JavaScript
43
star
17

charts-embed-sdk

The easiest way to embed MongoDB Charts visualisations into your web app
43
star
18

extended-json

On spec MongoDB Extended JSON parse and stringify
JavaScript
37
star
19

query-parser

Safe parsing and validation for MongoDB queries (filters), projections, and more.
TypeScript
36
star
20

jsonpatch-to-mongodb

Convert JSON patches into a MongoDB update
JavaScript
34
star
21

mongodb-language-model

Parses MongoDB query language and creates hierarchical Ampersand.js models to interact with the query tree
JavaScript
34
star
22

dataset-generator

๐Ÿšง What's a database without any data?
JavaScript
33
star
23

connect-backbone-to-react

Connect Backbone Models and Collections to React.
JavaScript
27
star
24

pretty-repl

Extends Node's repl.REPLServer to allow for a colorize function.
JavaScript
24
star
25

mongodb-extjson

MongoDB Extended JSON library
JavaScript
21
star
26

electron-license

Tools for electron apps to work with licenses.
JavaScript
18
star
27

devtools-shared

Shared dependencies of Compass, the MongoDB extension for VSCode and mongosh
TypeScript
14
star
28

log

๐Ÿšง Parse MongoDB log lines into objects
JavaScript
13
star
29

mongodb-download

JavaScript
12
star
30

mongo-views

Virtual collections - aka views with joins - in the MongoDB shell.
JavaScript
11
star
31

electron-installer-codesign

Sign your electron apps on OSX.
JavaScript
11
star
32

collection-sample

Sample documents from MongoDB collections.
JavaScript
11
star
33

mongodb-connection-string-url

MongoDB connection strings, based on the WhatWG URL API
TypeScript
10
star
34

node-codesign

Sign Node.js apps for MacOS.
JavaScript
10
star
35

connection-model

MongoDB connection model.
JavaScript
10
star
36

mongodb-js

Discussion, community, and best practices
8
star
37

mongodb-resumetoken-decoder

A library for decoding MongoDB resume tokens
TypeScript
8
star
38

react-mapbox-gl-leaflet

React wrapper of mapbox-gl-leaflet for react-leaflet. Demo: https://mongodb-js.github.io/react-mapbox-gl-leaflet
JavaScript
8
star
39

data-service

The MongoDB Data Service
JavaScript
7
star
40

morelikethis

Create more data that has the same shape as existing data.
JavaScript
7
star
41

nodejs-mongodb-legacy

Node.js MongoDB Driver With Legacy Callback Support
JavaScript
6
star
42

compass-import-export

Compass Import/Export Plugin
JavaScript
6
star
43

ace-autocompleter

Ace Editor Autocompleter for MongoDB Queries/Agg Pipelines
JavaScript
6
star
44

download-url

Lookup download URL's for MongoDB versions.
TypeScript
6
star
45

compass-plugin

A khaos template to create internal Compass packages.
Less
5
star
46

interruptor

Run a function with the possibility to interrupt it from another thread
C++
4
star
47

codemirror-mongodb

MongoDB integration for codemirror
JavaScript
4
star
48

system-ca

Access the system certificate store on Windows, macOS and Linux
TypeScript
4
star
49

devtools-docker-test-envs

Docker images and setups for testing
Shell
4
star
50

devtools-connect

A connection establishment utility for MongoDB developer tools
TypeScript
4
star
51

hadron-build

Complete tooling for large-scale Electron apps.
JavaScript
4
star
52

hadron-react

Monorepo for Hadron React Components
JavaScript
4
star
53

electron-installer-run

Run child processes safely handling all sorts of edge cases.
JavaScript
4
star
54

react-d3-unmanaged-wrapper

React component that wraps d3 code inside a div or svg container.
JavaScript
3
star
55

errors

Helpers for handling errors from the MongoDB driver.
JavaScript
3
star
56

compass-schema

Compass plugin for visualizing the inferred schema of a MongoDB collection
JavaScript
3
star
57

index-model

MongoDB index model.
JavaScript
3
star
58

shell

#wip Workspace and docs for MongoDB Shell
JavaScript
3
star
59

is-mongodb-running

Is MongoDB running? What port is it using?
JavaScript
3
star
60

app-migrations

Helper for application schema migrations.
JavaScript
3
star
61

intellij

MongoDB for IntelliJ
Kotlin
3
star
62

win-export-certificate-and-key

Export a certificate and its corresponding private key from the Windows CA store
C++
3
star
63

ejson-shell-parser

TypeScript
3
star
64

redact

Remove potentially sensitive information from objects without changing the shape.
JavaScript
3
star
65

pkg-rpm

Create a RedHat-RPM package for a Node.js executable.
JavaScript
2
star
66

resolve-mongodb-srv

Resolve mongodb+srv:// URLs to mongodb:// URLs
TypeScript
2
star
67

mongodb-mock-server

A mock server useful for testing difficult to reproduce cases in MongoDB drivers
JavaScript
2
star
68

objfuscate

Obfuscates JSON object values recursively, and keys if desired.
JavaScript
2
star
69

compass-connect

Compass plugin for connecting to MongoDB.
JavaScript
2
star
70

backbone-parentmodel

Extensions to Backbone.Model to support nested models and collections
JavaScript
2
star
71

mongodb-schema-parser

WASM/Rust Schema Parser for MongoDB
Rust
2
star
72

compass-collection

Compass Collection Plugin
JavaScript
2
star
73

precommit

Standard linting, formatting and more for mongodb-js projects.
JavaScript
2
star
74

macos-export-certificate-and-key

Export a certificate and its corresponding private key from the default keychain
C++
2
star
75

mongodb-js.github.io

CSS
2
star
76

jsonpath-to-dot

Convert a JSONPath into dotnotation
JavaScript
2
star
77

expression-to-mql

parse arithmetic expressions and convert them to MongoDB aggregation expressions
JavaScript
2
star
78

url

Extend mongodb-uri for more flexibility and data packing.
JavaScript
2
star
79

notary-service-client

๐Ÿ” A client for our notary-service (an API for codesigning).
JavaScript
2
star
80

mongodb-build-info

Extract information from mongodb's buildInfo
JavaScript
2
star
81

electron-wix-msi

TypeScript
2
star
82

ns

MongoDB namespace string (db.collection) parsing and validation
JavaScript
1
star
83

leafygreen-ui-starter-kit

Starter kit for making an application with leafygreen-ui
JavaScript
1
star
84

hadron-application-menu

Atom's application-menu class as a standalone module.
JavaScript
1
star
85

hadron-ipc

Simplified IPC for electron apps.
JavaScript
1
star
86

compass-query-bar

Renders a component for executing MongoDB queries through a GUI.
JavaScript
1
star
87

eslint-config

Shared eslint config for mongodb-js
JavaScript
1
star
88

vscode-mongodb-language

The MongoDB language support for VSCode
TypeScript
1
star
89

compass-database

Compass Database Plugin
Less
1
star
90

metrics

Shareable metric recording.
JavaScript
1
star
91

scope-client

The client to talk to scout-server from node.js or the browser
JavaScript
1
star
92

mongodb-log-writer

A library for writing MongoDB logv2 messages
TypeScript
1
star
93

mongodb-crypt-library-version

Get the version of a MongoDB crypt_shared library programmatically and as a CLI
C++
1
star
94

juttle-mongodb-adapter

2017 skunkworks project
JavaScript
1
star
95

ace-mode

The ACE mode for BSON types.
JavaScript
1
star
96

compass-home

Less
1
star
97

compass-explain-plan

Compass Explain Plan Plugin
JavaScript
1
star
98

learn-mongodb-docs

Main Driver Portal
JavaScript
1
star
99

compass-sidebar

Sidebar plugin
JavaScript
1
star
100

explain-plan-model

Model abstraction for MongoDB explain plans.
JavaScript
1
star