Gathering detailed insights and metrics for mongodb-core
Gathering detailed insights and metrics for mongodb-core
Gathering detailed insights and metrics for mongodb-core
Gathering detailed insights and metrics for mongodb-core
to-mongodb-core
Turns a mongojs or mongodb driver instance to a mongodb-core instance.
mongodb-memory-server-core
MongoDB Server for testing (core package, without autodownload). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.
mongodb
The official MongoDB driver for Node.js
mongodb-connection-string-url
MongoDB connection strings, based on the WhatWG URL API
MongoDB core driver functionality aims to make the "smallest" viable driver api
npm install mongodb-core
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
191 Stars
1,812 Commits
106 Forks
15 Watching
22 Branches
52 Contributors
Updated on 26 Jan 2024
Minified
Minified + Gzipped
JavaScript (99.69%)
Shell (0.27%)
Makefile (0.04%)
Cumulative downloads
Total Downloads
Last day
36.2%
41,302
Compared to previous day
Last week
17.2%
235,245
Compared to previous week
Last month
18.7%
809,962
Compared to previous month
Last year
-31.6%
9,450,587
Compared to previous year
4
13
1
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.
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/ |
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.
http://jira.mongodb.org/browse/NODE
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.
1{ 2 "name": "myproject", 3 "version": "1.0.0", 4 "description": "My first project", 5 "main": "index.js", 6 "repository": { 7 "type": "git", 8 "url": "git://github.com/christkv/myfirstproject.git" 9 }, 10 "dependencies": { 11 "mongodb-core": "~1.0" 12 }, 13 "author": "Christian Kvalheim", 14 "license": "Apache 2.0", 15 "bugs": { 16 "url": "https://github.com/christkv/myfirstproject/issues" 17 }, 18 "homepage": "https://github.com/christkv/myfirstproject" 19}
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.
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.
1var Server = require('mongodb-core').Server 2 , assert = require('assert'); 3 4// Set up server connection 5var server = new Server({ 6 host: 'localhost' 7 , port: 27017 8 , reconnect: true 9 , reconnectInterval: 50 10}); 11 12// Add event listeners 13server.on('connect', function(_server) { 14 console.log('connected'); 15 test.done(); 16}); 17 18server.on('close', function() { 19 console.log('closed'); 20}); 21 22server.on('reconnect', function() { 23 console.log('reconnect'); 24}); 25 26// Start connection 27server.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.
1var Server = require('mongodb-core').Server 2 , assert = require('assert'); 3 4// Set up server connection 5var server = new Server({ 6 host: 'localhost' 7 , port: 27017 8 , reconnect: true 9 , reconnectInterval: 50 10}); 11 12// Add event listeners 13server.on('connect', function(_server) { 14 console.log('connected'); 15 16 // Execute the ismaster command 17 _server.command('system.$cmd', {ismaster: true}, function(err, result) { 18 19 // Perform a document insert 20 _server.insert('myproject.inserts1', [{a:1}, {a:2}], { 21 writeConcern: {w:1}, ordered:true 22 }, function(err, results) { 23 assert.equal(null, err); 24 assert.equal(2, results.result.n); 25 26 // Perform a document update 27 _server.update('myproject.inserts1', [{ 28 q: {a: 1}, u: {'$set': {b:1}} 29 }], { 30 writeConcern: {w:1}, ordered:true 31 }, function(err, results) { 32 assert.equal(null, err); 33 assert.equal(1, results.result.n); 34 35 // Remove a document 36 _server.remove('myproject.inserts1', [{ 37 q: {a: 1}, limit: 1 38 }], { 39 writeConcern: {w:1}, ordered:true 40 }, function(err, results) { 41 assert.equal(null, err); 42 assert.equal(1, results.result.n); 43 44 // Get a document 45 var cursor = _server.cursor('integration_tests.inserts_example4', { 46 find: 'integration_tests.example4' 47 , query: {a:1} 48 }); 49 50 // Get the first document 51 cursor.next(function(err, doc) { 52 assert.equal(null, err); 53 assert.equal(2, doc.a); 54 55 // Execute the ismaster command 56 _server.command("system.$cmd" 57 , {ismaster: true}, function(err, result) { 58 assert.equal(null, err) 59 _server.destroy(); 60 }); 61 }); 62 }); 63 }); 64 65 test.done(); 66 }); 67}); 68 69server.on('close', function() { 70 console.log('closed'); 71}); 72 73server.on('reconnect', function() { 74 console.log('reconnect'); 75}); 76 77// Start connection 78server.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.
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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 16/29 approved changesets -- score normalized to 5
Reason
project is archived
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
57 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More