Solution for a MongoDB-like portable database.
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. By participating, you are expected to uphold this code. Please report unacceptable behavior to eduardo.astolfi91.com.
npm install mongo-portable
yarn add mongo-portable
// 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 and Collection (and Cursor when using the "doNotFetch" option).
Handles the database, collections and connections.
Read the full API documentation here
Handles the list of documents by using cursors.
Read the full API documentation here
Fetchs and access the documents to return them to the client.
Read the full API documentation here
It is located in a separated module, so install it by:
npm install file-system-store
yarn add file-system-store
And then use it in your application by adding it in your MongoPortable instance:
import { FileSystemStore } from "file-system-store";
db.addStore(new FileSystemStore(/* options */));
or as a middleware:
import { FileSystemStore } from "file-system-store";
db.use("store", new FileSystemStore(/* options */));
View the package here and read the full API documentation here
Feel free to contribute with your own ideas / fixes!
There is a to-do list with the features I'd like to add in the feature, and a serie of milestones with the roadmap I have in mind. Take a look at them if you want to :)
Every contribution should be addressed with a well-formed pull request -> Contributing
Generated using TypeDoc