Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@seald-io/nedb

Package Overview
Dependencies
Maintainers
3
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@seald-io/nedb - npm Package Compare versions

Comparing version 2.0.0-1 to 2.0.0-4

6

package.json
{
"name": "@seald-io/nedb",
"version": "2.0.0-1",
"version": "2.0.0-4",
"files": [

@@ -31,6 +31,6 @@ "lib/**/*.js",

],
"homepage": "https://github.com/louischatriot/nedb",
"homepage": "https://github.com/seald/nedb",
"repository": {
"type": "git",
"url": "git@github.com:louischatriot/nedb.git"
"url": "git@github.com:seald/nedb.git"
},

@@ -37,0 +37,0 @@ "dependencies": {

@@ -8,4 +8,4 @@ <img src="http://i.imgur.com/9O1xHFb.png" style="width: 25%; height: 25%; float: left;">

Since the original maintainer doesn't support this package anymore, we forked
it and maintain it for the needs of [Seald](https://www.seald.io).
Since the original maintainer doesn't support this package anymore, we forked it
and maintain it for the needs of [Seald](https://www.seald.io).

@@ -17,10 +17,11 @@ **Embedded persistent or in memory database for Node.js, nw.js, Electron and

## Installation, tests
Module name on npm and bower is `@seald-io/nedb`.
Module name on npm is `@seald-io/nedb`.
```
npm install @seald-io/nedb --save # Put latest version in your package.json
npm test # You'll need the dev dependencies to launch tests
npm install @seald-io/nedb
```
## API
It is a subset of MongoDB's API (the most used operations).

@@ -112,15 +113,15 @@

// Type 1: In-memory only datastore (no need to load the database)
var Datastore = require('nedb')
, db = new Datastore();
const Datastore = require('@seald-io/nedb')
const db = new Datastore()
// Type 2: Persistent datastore with manual loading
var Datastore = require('nedb')
, db = new Datastore({ filename: 'path/to/datafile' });
const Datastore = require('@seald-io/nedb')
const db = new Datastore({ filename: 'path/to/datafile' })
db.loadDatabase(function (err) { // Callback is optional
// Now commands will be executed
});
})
// Type 3: Persistent datastore with automatic loading
var Datastore = require('nedb')
, db = new Datastore({ filename: 'path/to/datafile', autoload: true });
const Datastore = require('@seald-io/nedb')
const db = new Datastore({ filename: 'path/to/datafile', autoload: true });
// You can issue commands right away

@@ -130,6 +131,5 @@

// For example on Linux, the datafile will be ~/.config/nwtest/nedb-data/something.db
var Datastore = require('nedb')
, path = require('path')
,
db = new Datastore({ filename: path.join(require('nw.gui').App.dataPath, 'something.db') });
const Datastore = require('@seald-io/nedb')
const path = require('path')
const db = new Datastore({ filename: path.join(require('nw.gui').App.dataPath, 'something.db') });

@@ -180,5 +180,5 @@ // Of course you can create multiple datastores if you need several

syncs. Usually syncs are 30 seconds appart so that's at most 30 seconds of
data. [This post by Antirez on Redis persistence](http://oldblog.antirez.com/post/redis-persistence-demystified.html) explains this in more details,
NeDB being very close to Redis AOF persistence with `appendfsync` option set
to `no`.
data. [This post by Antirez on Redis persistence](http://oldblog.antirez.com/post/redis-persistence-demystified.html)
explains this in more details, NeDB being very close to Redis AOF persistence
with `appendfsync` option set to `no`.

@@ -200,11 +200,11 @@ ### Inserting documents

var doc = {
hello: 'world'
, n: 5
, today: new Date()
, nedbIsAwesome: true
, notthere: null
, notToBeSaved: undefined // Will not be saved
, fruits: ['apple', 'orange', 'pear']
, infos: { name: 'nedb' }
};
hello: 'world',
n: 5,
today: new Date(),
nedbIsAwesome: true,
notthere: null,
notToBeSaved: undefined, // Will not be saved
fruits: ['apple', 'orange', 'pear'],
infos: { name: '@seald-io/nedb' }
}

@@ -214,3 +214,3 @@ db.insert(doc, function (err, newDoc) { // Callback is optional

// newDoc has no key called notToBeSaved since its value was undefined
});
})
```

@@ -226,3 +226,3 @@

// newDocs is an array with these documents, augmented with their _id
});
})

@@ -233,3 +233,3 @@ // If there is a unique constraint on field 'a', this will fail

// The database was not modified
});
})
```

@@ -272,3 +272,3 @@

// If no document is found, docs is equal to []
});
})

@@ -278,3 +278,3 @@ // Finding all planets whose name contain the substring 'ar' using a regular expression

// docs contains Mars and Earth
});
})

@@ -284,22 +284,22 @@ // Finding all inhabited planets in the solar system

// docs is an array containing document Earth only
});
})
// Use the dot-notation to match fields in subdocuments
db.find({ "humans.genders": 2 }, function (err, docs) {
db.find({ 'humans.genders': 2 }, function (err, docs) {
// docs contains Earth
});
})
// Use the dot-notation to navigate arrays of subdocuments
db.find({ "completeData.planets.name": "Mars" }, function (err, docs) {
db.find({ 'completeData.planets.name': 'Mars' }, function (err, docs) {
// docs contains document 5
});
})
db.find({ "completeData.planets.name": "Jupiter" }, function (err, docs) {
db.find({ 'completeData.planets.name': 'Jupiter' }, function (err, docs) {
// docs is empty
});
})
db.find({ "completeData.planets.0.name": "Earth" }, function (err, docs) {
db.find({ 'completeData.planets.0.name': 'Earth' }, function (err, docs) {
// docs contains document 5
// If we had tested against "Mars" docs would be empty because we are matching against a specific array element
});
// If we had tested against 'Mars' docs would be empty because we are matching against a specific array element
})

@@ -309,7 +309,7 @@ // You can also deep-compare objects. Don't confuse this with dot-notation!

// docs is empty, because { genders: 2 } is not equal to { genders: 2, eyes: true }
});
})
// Find all documents in the collection
db.find({}, function (err, docs) {
});
})

@@ -320,3 +320,3 @@ // The same rules apply when you want to only find one document

// If no document is found, doc is null
});
})
```

@@ -343,5 +343,5 @@

// $lt, $lte, $gt and $gte work on numbers and strings
db.find({ "humans.genders": { $gt: 5 } }, function (err, docs) {
db.find({ 'humans.genders': { $gt: 5 } }, function (err, docs) {
// docs contains Omicron Persei 8, whose humans have more than 5 genders (7).
});
})

@@ -356,3 +356,3 @@ // When used with strings, lexicographical order is used

// docs contains Earth and Jupiter
});
})

@@ -362,3 +362,3 @@ // Using $stat

// docs contains only Mars
});
})

@@ -373,3 +373,3 @@ // Using $regex with another operator

// docs only contains Mars because Earth was excluded from the match by $nin
});
})
```

@@ -410,3 +410,3 @@

// docs contains documents with id 5 (completeData)
});
})

@@ -424,3 +424,3 @@ db.find({

// docs is empty
});
})

@@ -439,3 +439,3 @@ // You can use inside #elemMatch query any known document query operator

// docs contains documents with id 5 (completeData)
});
})

@@ -445,7 +445,7 @@ // Note: you can't use nested comparison functions, e.g. { $size: { $lt: 5 } } will throw an error

// docs contains Mars
});
})
db.find({ satellites: { $size: 1 } }, function (err, docs) {
// docs is empty
});
})

@@ -455,3 +455,3 @@ // If a document's field is an array, matching it means matching any element of the array

// docs contains Mars. Result would have been the same if query had been { satellites: 'Deimos' }
});
})

@@ -461,3 +461,3 @@ // This also works for queries that use comparison operators

// docs is empty since Phobos and Deimos are after Amos in lexicographical order
});
})

@@ -467,3 +467,3 @@ // This also works with the $in and $nin operator

// docs contains Mars (the Earth document is not complete!)
});
})
```

@@ -478,3 +478,3 @@

* For `$where`, the syntax
is `{ $where: function () { /* object is "this", return a boolean */ } }`
is `{ $where: function () { /* object is 'this', return a boolean */ } }`

@@ -484,11 +484,11 @@ ```javascript

// docs contains Earth and Mars
});
})
db.find({ $not: { planet: 'Earth' } }, function (err, docs) {
// docs contains Mars, Jupiter, Omicron Persei 8
});
})
db.find({ $where: function () { return Object.keys(this) > 6; } }, function (err, docs) {
// docs with more than 6 properties
});
})

@@ -501,3 +501,3 @@ // You can mix normal queries, comparison queries and logical operators

// docs contains Earth
});
})

@@ -522,3 +522,3 @@ ```

// docs is [doc3, doc1]
});
})

@@ -528,3 +528,3 @@ // You can sort in reverse order like this

// docs is [doc1, doc3, doc2]
});
})

@@ -550,3 +550,3 @@ // You can sort on one field, then another, and so on like this:

// docs is [{ planet: 'Mars', system: 'solar', _id: 'id1' }]
});
})

@@ -560,3 +560,3 @@ // Keeping only the given fields but removing _id

// docs is [{ planet: 'Mars', system: 'solar' }]
});
})

@@ -570,3 +570,3 @@ // Omitting only the given fields and removing _id

// docs is [{ inhabited: false, satellites: ['Phobos', 'Deimos'] }]
});
})

@@ -576,3 +576,3 @@ // Failure: using both modes at the same time

// err is the error message, docs is undefined
});
})

@@ -585,3 +585,3 @@ // You can also use it in a Cursor way but this syntax is not compatible with MongoDB

// docs is [{ planet: 'Mars', system: 'solar', _id: 'id1' }]
});
})

@@ -594,3 +594,3 @@ // Project on a nested document

// doc is { planet: 'Earth', _id: 'id2', humans: { genders: 2 } }
});
})
```

@@ -647,3 +647,4 @@

API was changed between v1.7.4 and v1.8. Please refer to
the [change log](https://github.com/louischatriot/nedb/wiki/Change-log" target="_blank) to see the change.
the [previous changelog](https://github.com/louischatriot/nedb/wiki/Change-log)
to see the change.
* For an upsert, `affectedDocuments` contains the inserted document and

@@ -662,3 +663,3 @@ the `upsert` flag is set to `true`.

```javascript
// Let's use the same example collection as in the "finding document" part
// Let's use the same example collection as in the 'finding document' part
// { _id: 'id1', planet: 'Mars', system: 'solar', inhabited: false }

@@ -686,4 +687,4 @@ // { _id: 'id2', planet: 'Earth', system: 'solar', inhabited: true }

$set: {
"data.satellites": 2,
"data.red": true
'data.satellites': 2,
'data.red': true
}

@@ -700,3 +701,3 @@ }, {}, function () {

// }
// You lost the "data.red" field which is probably not the intended behavior
// You lost the 'data.red' field which is probably not the intended behavior
});

@@ -712,3 +713,6 @@ });

// Upserting a document
db.update({ planet: 'Pluton' }, { planet: 'Pluton', inhabited: false }, { upsert: true }, function (err, numReplaced, upsert) {
db.update({ planet: 'Pluton' }, {
planet: 'Pluton',
inhabited: false
}, { upsert: true }, function (err, numReplaced, upsert) {
// numReplaced = 1, upsert = { _id: 'id5', planet: 'Pluton', inhabited: false }

@@ -764,3 +768,10 @@ // A new document { _id: 'id5', planet: 'Pluton', inhabited: false } has been added to the collection

// If $slice is specified but not $each, $each is set to []
db.update({ _id: 'id6' }, { $push: { fruits: { $each: ['banana'], $slice: 2 } } }, {}, function () {
db.update({ _id: 'id6' }, {
$push: {
fruits: {
$each: ['banana'],
$slice: 2
}
}
}, {}, function () {
// Now the fruits array is ['apple', 'orange']

@@ -871,5 +882,5 @@ });

// Format of the error message when the unique constraint is not met
db.insert({ somefield: 'nedb' }, function (err) {
db.insert({ somefield: '@seald-io/nedb' }, function (err) {
// err is null
db.insert({ somefield: 'nedb' }, function (err) {
db.insert({ somefield: '@seald-io/nedb' }, function (err) {
// err is { errorType: 'uniqueViolated'

@@ -967,21 +978,16 @@ // , key: 'name'

* [connect-nedb-session](https://github.com/louischatriot/connect-nedb-session) is a session store for Connect and
Express, backed by nedb
* If you mostly use NeDB for logging purposes and don't want the memory
footprint of your application to grow too large, you can
use [NeDB Logger](https://github.com/louischatriot/nedb-logger) to insert documents in a NeDB-readable database
* If you've outgrown NeDB, switching to MongoDB won't be too hard as it is the
same API.
Use [this utility](https://github.com/louischatriot/nedb-to-mongodb) to transfer the data from a NeDB database to a MongoDB
collection
* An ODM for
NeDB: [Camo](https://github.com/scottwrobinson/camo" target="_blank)
* An ODM for NeDB: [follicle](https://github.com/seald/follicle)
## Pull requests
## Modernization
**Important: I consider NeDB to be feature-complete, i.e. it does everything I
think it should and nothing more. As a general rule I will not accept pull
requests anymore, except for bugfixes (of course) or if I get convinced I
overlook a strong usecase. Please make sure to open an issue before spending
time on any PR.**
This fork of NeDB will be incrementally updated to:
- remove deprecated features;
- use `async` functions and `Promises` instead of callbacks with `async@0.2.6`;
- expose a `Promise`-based interface;
- remove the `underscore` dependency;
- add a way to change the `Storage` module by dependency injection, which will
pave the way to a cleaner browser version, and eventually other `Storage`
backends such as `react-native` to
replace [`react-native-local-mongodb`](https://github.com/antoniopresto/react-native-local-mongodb/)
which is discontinued.

@@ -997,4 +1003,4 @@ If you submit a pull request, thanks! There are a couple rules to follow though

* Please stick to the current coding style. It's important that the code uses a
coherent style for readability.
* Do not include sylistic improvements ("housekeeping"). If you think one part
coherent style for readability (this package uses [`standard`](https://standardjs.com/)).
* Do not include stylistic improvements ('housekeeping'). If you think one part
deserves lots of housekeeping, use a separate pull request so as not to

@@ -1004,4 +1010,2 @@ pollute the code.

test suite before submitting to make sure you didn't introduce regressions.
* Do not build the browser version in your branch, I'll take care of it once the
code is merged.
* Update the readme accordingly.

@@ -1031,3 +1035,2 @@ * Last but not least: keep in mind what NeDB's mindset is! The goal is not to be

in the issue.
* The code should be Javascript, not Coffeescript.

@@ -1034,0 +1037,0 @@ ## License

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc