mongo-portable
Version:
Portable Pure JS MongoDB - Based on Monglodb (https://github.com/euforic/monglodb.git) by Christian Sullivan (http://RogueSynaptics.com)
131 lines (97 loc) • 4.95 kB
Markdown
Solution for a MongoDB-like portable database.
[![Package Version][npm-image]][npm-url]
[![NodeJS Version][node-image]][node-url]
[![Travis Build][travis-image]][travis-url]
[![Appveyor Build][appveyor-image]][appveyor-url]
[![Codeship Build][codeship-image]][codeship-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Downloads][downloads-image]][npm-url]
[![Documentation Status][docs-image]][docs-url]
MongoPortable is a module that handles collections and documents in memory, and allow the use of stores for persistence.
This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md).
By participating, you are expected to uphold this code. Please report unacceptable behavior to eduardo.astolfi91.com.
```shell
npm install mongo-portable
yarn add mongo-portable
```
```javascript
// Declaring the module dependency
import { MongoPortable } from "mongo-portable";
// Instantiates a new ddbb object by passing a ddbb name
let db = new MongoPortable("DB_NAME");
// Creates a new collection named "users"
// (if it's already created, it will just return it instead)
db.collection("users").then(collection => {
// Inserts a new document into the collection
collection.insert({ name: "John", lastName: "Abruzzi" }).then(document => {
console.log(document); // -> { name: "John", lastName: "Abruzzi" }
// Performs a query against this collection, fetching all the results
users.find({ name: "John" }).then(documents => {
console.log(documents); // -> [ { name: "John", lastName: "Abruzzi" } ]
});
});
});
```
The main modules available are [MongoPortable](
Handles the database, collections and connections.
Read the full API documentation [here][API-MongoPortable]
Handles the list of documents by using cursors.
Read the full API documentation [here][API-Collection]
Fetchs and access the documents to return them to the client.
Read the full API documentation [here][API-Cursor]
----------
It is located in a separated module, so install it by:
```shell
npm install file-system-store
yarn add file-system-store
```
And then use it in your application by adding it in your MongoPortable instance:
```javascript
import { FileSystemStore } from "file-system-store";
db.addStore(new FileSystemStore(/* options */));
```
or as a middleware:
```javascript
import { FileSystemStore } from "file-system-store";
db.use("store", new FileSystemStore(/* options */));
```
View the package [here][Module-FileSystemStore] and read the full API documentation [here][API-FileSystemStore]
----------
Feel free to contribute with your own ideas / fixes!
There is a [to-do list](
Take a look at them if you want to :)
Every contribution should be addressed with a well-formed pull request -> [Contributing](CONTRIBUTING.md)
----------
[](LICENSE.txt)
[]: https://docs.mongodb.com/manual/reference/command/
[]: https://github.com/EastolfiWebDev/MongoPortable/blob/master/api/MongoPortable.md
[]: https://github.com/EastolfiWebDev/MongoPortable/blob/master/api/Collection.md
[]: https://github.com/EastolfiWebDev/MongoPortable/blob/master/api/Cursor.md
[]: https://github.com/EastolfiWebDev/FileSystemStore
[]: https://github.com/EastolfiWebDev/FileSystemStore/blob/master/api/FileSystemStore.md
[]: https://img.shields.io/npm/v/mongo-portable.svg?label=Package%20Version
[]: https://www.npmjs.com/package/mongo-portable
[]: https://img.shields.io/badge/node-v4.4.0-blue.svg?label=Node%20Version
[]: https://nodejs.org/en/
[]: https://img.shields.io/travis/EastolfiWebDev/MongoPortable.svg?label=linux
[]: https://travis-ci.org/EastolfiWebDev/MongoPortable
[]: https://img.shields.io/appveyor/ci/eastolfi/MongoPortable/master.svg?label=windows
[]: https://ci.appveyor.com/project/eastolfi/mongoportable
[]: https://codeship.com/projects/d57e8820-5e10-0134-8b6d-42ae3f63aed8/status?branch=master
[]: https://codeship.com/projects/174143
[]: https://coveralls.io/repos/github/EastolfiWebDev/MongoPortable/badge.svg?branch=master
[]: https://coveralls.io/github/EastolfiWebDev/MongoPortable?branch=master
[]: https://img.shields.io/npm/dt/mongo-portable.svg
[]: https://readthedocs.org/projects/mongoportable/badge/?version=latest
[]: http://mongoportable.readthedocs.io/en/latest/?badge=latest