MongoPortable
Solution for a MongoDB-like portable database.
It handles the collections and documents in memory, and allow the use of stores for persistence.
Installation
npm install --save mongo-portable
Usage
// Declaring the module dependency
var MongoPortable = require("mongo-portable").MongoPortable;
// Instantiates a new ddbb object by passing a ddbb name
var db = new MongoPortable("TEST");
// Creates a new collection named "users"
// (if it's already created, it will just return it instead)
var users = db.collection("users");
// Inserts a new document into the collection
var document = users.insert({ name: "John", lastName: "Abruzzi" });
console.log(document); // -> { name: "John", lastName: "Abruzzi" }
// Creates a cursor with the query information, ready to be fetched
var cursor = users.find({ name: "John" });
// Iterates over the cursor, obtaining each document that matchs the query
cursor.forEach(function(doc) {
console.log(doc); // -> { name: "John", lastName: "Abruzzi" }
});
Modules
The modules visibles for an application are MongoPortable, Collection and Cursor.
MongoPortable
Handles the database, collections and connections.
Read the full API documentation here
Collection
Handles the list of documents by using cursors.
Read the full API documentation here
Cursor
Fetchs and access the documents to return them to the client.
Read the full API documentation here
Stores
File System Store
It is located in a separated module, so install it by:
npm install --save file-system-store
And then use it in your application by adding it in your MongoPortable instance:
var FileSystemStore = require("file-system-store");
db.addStore(FileSystemStore);
or as a middleware:
var FileSystemStore = require("file-system-store");
db.use("store", FileSystemStore);
View the package here and read the full API documentation here
TO-DO List
Database Operations
-
DDBB
- .use() (Middleware)
- .addStore()
- .dropDatabase()
- Connections
-
Collections
- .collectionsInfo()
- .collections()
- .collectionNames()
- .collection()
- .dropCollection()
- .renameCollection()
- .dropCollection()
- .dropCollection()
- .dropCollection()
-
Indexes
- .createIndex()
- .ensureIndex()
- .dropIndex()
- .reIndex()
- .indexInformation()
-
db.runCommand()
- User Commands
- Database Operations
- Internal Commands
- Testing Commands
- Auditing Commands
Read the full API documentation here
Collection
-
Creating
- .insert()
-
Reading
- .find()
- .findOne()
-
Updating
- .update()
-
Deleting
- .remove()
Read the full API documentation here
Cursor
-
Fetching
- .rewind()
- .forEach()
- .map()
- .hasNext()
- .next()
- .fetchAll()
- .fetchOne()
- .count()
- .sort()
- .skip()
- .limit()
-
Managing
- .batchSize()
- .close()
- .comment()
- .explain()
- .hint()
- .itcount()
- .maxScan()
- .maxTimeMS()
- .max()
- .min()
- .noCursorTimeout()
- .objsLeftInBatch()
- .pretty()
- .readConcern()
- .readPref()
- .returnKey()
- .showRecordId()
- .size()
- .snapshot()
- .tailable()
- .toArray()
Read the full API documentation here
License
MIT