UNPKG

mongo-portable

Version:

Portable Pure JS MongoDB - Based on Monglodb (https://github.com/euforic/monglodb.git) by Christian Sullivan (http://RogueSynaptics.com)

365 lines (360 loc) 20.9 kB
<!doctype html> <html class="default no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Mongo Portable</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="assets/css/main.css"> </head> <body> <header> <div class="tsd-page-toolbar"> <div class="container"> <div class="table-wrap"> <div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base="."> <div class="field"> <label for="tsd-search-field" class="tsd-widget search no-caption">Search</label> <input id="tsd-search-field" type="text" /> </div> <ul class="results"> <li class="state loading">Preparing search index...</li> <li class="state failure">The search index is not available</li> </ul> <a href="index.html" class="title">Mongo Portable</a> </div> <div class="table-cell" id="tsd-widgets"> <div id="tsd-filter"> <a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a> <div class="tsd-filter-group"> <div class="tsd-select" id="tsd-filter-visibility"> <span class="tsd-select-label">All</span> <ul class="tsd-select-list"> <li data-value="public">Public</li> <li data-value="protected">Public/Protected</li> <li data-value="private" class="selected">All</li> </ul> </div> <input type="checkbox" id="tsd-filter-inherited" checked /> <label class="tsd-widget" for="tsd-filter-inherited">Inherited</label> <input type="checkbox" id="tsd-filter-only-exported" /> <label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label> </div> </div> <a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a> </div> </div> </div> </div> <div class="tsd-page-title"> <div class="container"> <ul class="tsd-breadcrumb"> <li> <a href="globals.html">Globals</a> </li> </ul> <h1> Mongo Portable</h1> </div> </div> </header> <div class="container container-main"> <div class="row"> <div class="col-8 col-content"> <div class="tsd-panel tsd-typography"> <h1 id="mongoportable">MongoPortable</h1> <p>Solution for a MongoDB-like portable database.</p> <p><a href="https://www.npmjs.com/package/mongo-portable"><img src="https://img.shields.io/npm/v/mongo-portable.svg?label=Package%20Version" alt="Package Version"></a> <a href="https://nodejs.org/en/"><img src="https://img.shields.io/badge/node-v4.4.0-blue.svg?label=Node%20Version" alt="NodeJS Version"></a></p> <p><a href="https://travis-ci.org/EastolfiWebDev/MongoPortable"><img src="https://img.shields.io/travis/EastolfiWebDev/MongoPortable.svg?label=linux" alt="Travis Build"></a> <a href="https://ci.appveyor.com/project/eastolfi/mongoportable"><img src="https://img.shields.io/appveyor/ci/eastolfi/MongoPortable/master.svg?label=windows" alt="Appveyor Build"></a> <a href="https://codeship.com/projects/174143"><img src="https://codeship.com/projects/d57e8820-5e10-0134-8b6d-42ae3f63aed8/status?branch=master" alt="Codeship Build"></a></p> <p><a href="https://coveralls.io/github/EastolfiWebDev/MongoPortable?branch=master"><img src="https://coveralls.io/repos/github/EastolfiWebDev/MongoPortable/badge.svg?branch=master" alt="Test Coverage"></a> <a href="https://www.npmjs.com/package/mongo-portable"><img src="https://img.shields.io/npm/dt/mongo-portable.svg" alt="Downloads"></a> <a href="http://mongoportable.readthedocs.io/en/latest/?badge=latest"><img src="https://readthedocs.org/projects/mongoportable/badge/?version=latest" alt="Documentation Status"></a></p> <p>MongoPortable is a module that handles collections and documents in memory, and allow the use of stores for persistence.</p> <p>This project adheres to the Contributor Covenant <a href="CODE_OF_CONDUCT.md">code of conduct</a>. By participating, you are expected to uphold this code. Please report unacceptable behavior to eduardo.astolfi91.com.</p> <h1 id="installation">Installation</h1> <pre><code class="lang-shell">npm install mongo-portable yarn add mongo-portable </code></pre> <h1 id="usage">Usage</h1> <pre><code class="lang-javascript"><span class="hljs-comment">// Declaring the module dependency</span> <span class="hljs-keyword">import</span> { MongoPortable } <span class="hljs-keyword">from</span> <span class="hljs-string">"mongo-portable"</span>; <span class="hljs-comment">// Instantiates a new ddbb object by passing a ddbb name</span> <span class="hljs-keyword">let</span> db = <span class="hljs-keyword">new</span> MongoPortable(<span class="hljs-string">"DB_NAME"</span>); <span class="hljs-comment">// Creates a new collection named "users" </span> <span class="hljs-comment">// (if it's already created, it will just return it instead)</span> db.collection(<span class="hljs-string">"users"</span>).then(<span class="hljs-function"><span class="hljs-params">collection</span> =&gt;</span> { <span class="hljs-comment">// Inserts a new document into the collection</span> collection.insert({ <span class="hljs-attr">name</span>: <span class="hljs-string">"John"</span>, <span class="hljs-attr">lastName</span>: <span class="hljs-string">"Abruzzi"</span> }).then(<span class="hljs-function"><span class="hljs-params">document</span> =&gt;</span> { <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">document</span>); <span class="hljs-comment">// -&gt; { name: "John", lastName: "Abruzzi" }</span> <span class="hljs-comment">// Performs a query against this collection, fetching all the results</span> users.find({ <span class="hljs-attr">name</span>: <span class="hljs-string">"John"</span> }).then(<span class="hljs-function"><span class="hljs-params">documents</span> =&gt;</span> { <span class="hljs-built_in">console</span>.log(documents); <span class="hljs-comment">// -&gt; [ { name: "John", lastName: "Abruzzi" } ]</span> }); }); }); </code></pre> <h1 id="modules">Modules</h1> <p>The main modules available are <a href="#MongoPortable">MongoPortable</a> and <a href="#Collection">Collection</a> (and <a href="#Cursor">Cursor</a> when using the &quot;doNotFetch&quot; option).</p> <h2 id="mongoportable">MongoPortable</h2> <p>Handles the database, collections and connections.</p> <p>Read the full API documentation <a href="https://github.com/EastolfiWebDev/MongoPortable/blob/master/api/MongoPortable.md">here</a></p> <h2 id="collection">Collection</h2> <p>Handles the list of documents by using cursors.</p> <p>Read the full API documentation <a href="https://github.com/EastolfiWebDev/MongoPortable/blob/master/api/Collection.md">here</a></p> <h2 id="cursor">Cursor</h2> <p>Fetchs and access the documents to return them to the client.</p> <p>Read the full API documentation <a href="https://github.com/EastolfiWebDev/MongoPortable/blob/master/api/Cursor.md">here</a></p> <hr> <h1 id="stores">Stores</h1> <h2 id="file-system-store">File System Store</h2> <p>It is located in a separated module, so install it by:</p> <pre><code class="lang-shell">npm install file-system-store yarn add file-system-store </code></pre> <p>And then use it in your application by adding it in your MongoPortable instance:</p> <pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { FileSystemStore } <span class="hljs-keyword">from</span> <span class="hljs-string">"file-system-store"</span>; db.addStore(<span class="hljs-keyword">new</span> FileSystemStore(<span class="hljs-comment">/* options */</span>)); </code></pre> <p>or as a middleware:</p> <pre><code class="lang-javascript"><span class="hljs-keyword">import</span> { FileSystemStore } <span class="hljs-keyword">from</span> <span class="hljs-string">"file-system-store"</span>; db.use(<span class="hljs-string">"store"</span>, <span class="hljs-keyword">new</span> FileSystemStore(<span class="hljs-comment">/* options */</span>)); </code></pre> <p>View the package <a href="https://github.com/EastolfiWebDev/FileSystemStore">here</a> and read the full API documentation <a href="https://github.com/EastolfiWebDev/FileSystemStore/blob/master/api/FileSystemStore.md">here</a></p> <hr> <h2 id="contributing">Contributing</h2> <p>Feel free to contribute with your own ideas / fixes!</p> <p>There is a <a href="#TO-DO List">to-do list</a> with the features I&#39;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 :)</p> <p>Every contribution should be addressed with a well-formed pull request -&gt; <a href="CONTRIBUTING.md">Contributing</a></p> <hr> <h1 id="license">License</h1> <p><a href="LICENSE.txt">MIT</a></p> </div> </div> <div class="col-4 col-menu menu-sticky-wrap menu-highlight"> <nav class="tsd-navigation primary"> <ul> <li class="globals "> <a href="globals.html"><em>Globals</em></a> </li> </ul> </nav> <nav class="tsd-navigation secondary menu-sticky"> <ul class="before-current"> <li class=" tsd-kind-class"> <a href="classes/aggregation.html" class="tsd-kind-icon">Aggregation</a> </li> <li class=" tsd-kind-class"> <a href="classes/basestore.html" class="tsd-kind-icon">Base<wbr>Store</a> </li> <li class=" tsd-kind-class"> <a href="classes/binaryparser.html" class="tsd-kind-icon">Binary<wbr>Parser</a> </li> <li class=" tsd-kind-class"> <a href="classes/binaryparserbuffer.html" class="tsd-kind-icon">Binary<wbr>Parser<wbr>Buffer</a> </li> <li class=" tsd-kind-class"> <a href="classes/collection.html" class="tsd-kind-icon">Collection</a> </li> <li class=" tsd-kind-class"> <a href="classes/connectionhelper.html" class="tsd-kind-icon">Connection<wbr>Helper</a> </li> <li class=" tsd-kind-class"> <a href="classes/cursor.html" class="tsd-kind-icon">Cursor</a> </li> <li class=" tsd-kind-class"> <a href="classes/document.html" class="tsd-kind-icon">Document</a> </li> <li class=" tsd-kind-class"> <a href="classes/eventemitter.html" class="tsd-kind-icon">Event<wbr>Emitter</a> </li> <li class=" tsd-kind-class"> <a href="classes/mongoportable.html" class="tsd-kind-icon">Mongo<wbr>Portable</a> </li> <li class=" tsd-kind-class"> <a href="classes/objectid.html" class="tsd-kind-icon">Object<wbr>Id</a> </li> <li class=" tsd-kind-class"> <a href="classes/options.html" class="tsd-kind-icon">Options</a> </li> <li class=" tsd-kind-class"> <a href="classes/selector.html" class="tsd-kind-icon">Selector</a> </li> <li class=" tsd-kind-class"> <a href="classes/selectormatcher.html" class="tsd-kind-icon">Selector<wbr>Matcher</a> </li> <li class=" tsd-kind-class"> <a href="classes/utils.html" class="tsd-kind-icon">Utils</a> </li> <li class=" tsd-kind-interface"> <a href="interfaces/iabstractstore.html" class="tsd-kind-icon">IAbstract<wbr>Store</a> </li> <li class=" tsd-kind-interface tsd-is-not-exported"> <a href="interfaces/iclause.html" class="tsd-kind-icon">IClause</a> </li> <li class=" tsd-kind-interface"> <a href="interfaces/iconnection.html" class="tsd-kind-icon">IConnection</a> </li> <li class=" tsd-kind-variable tsd-is-not-exported"> <a href="globals.html#machine_id" class="tsd-kind-icon">MACHINE_<wbr>ID</a> </li> <li class=" tsd-kind-variable tsd-is-not-exported"> <a href="globals.html#checkforhexregexp" class="tsd-kind-icon">check<wbr>For<wbr>Hex<wbr>Reg<wbr>Exp</a> </li> <li class=" tsd-kind-variable tsd-is-not-exported"> <a href="globals.html#chr" class="tsd-kind-icon">chr</a> </li> <li class=" tsd-kind-variable tsd-is-not-exported"> <a href="globals.html#database" class="tsd-kind-icon">database</a> </li> <li class=" tsd-kind-variable tsd-is-not-exported"> <a href="globals.html#maxbits" class="tsd-kind-icon">max<wbr>Bits</a> </li> <li class=" tsd-kind-variable tsd-is-not-exported"> <a href="globals.html#pid" class="tsd-kind-icon">pid</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#applymodifier" class="tsd-kind-icon">apply<wbr>Modifier</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#docomplexgroup" class="tsd-kind-icon">do<wbr>Complex<wbr>Group</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#dogroup" class="tsd-kind-icon">do<wbr>Group</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#domatch" class="tsd-kind-icon">do<wbr>Match</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#doproject" class="tsd-kind-icon">do<wbr>Project</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#dosinglegroup" class="tsd-kind-icon">do<wbr>Single<wbr>Group</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#dosort" class="tsd-kind-icon">do<wbr>Sort</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#ensurefindparams" class="tsd-kind-icon">ensure<wbr>Find<wbr>Params</a> </li> <li class=" tsd-kind-function tsd-is-private tsd-is-not-exported"> <a href="globals.html#getdocuments" class="tsd-kind-icon">get<wbr>Documents</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#getobjectsize" class="tsd-kind-icon">get<wbr>Object<wbr>Size</a> </li> <li class=" tsd-kind-function tsd-is-private tsd-is-not-exported"> <a href="globals.html#hassorting" class="tsd-kind-icon">has<wbr>Sorting</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#isvalidhexregexp" class="tsd-kind-icon">is<wbr>Valid<wbr>Hex<wbr>Reg<wbr>Exp</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#mapfields" class="tsd-kind-icon">map<wbr>Fields</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#modify" class="tsd-kind-icon">modify</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#testclause" class="tsd-kind-icon">test<wbr>Clause</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#testlogicalclause" class="tsd-kind-icon">test<wbr>Logical<wbr>Clause</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#testobjectclause" class="tsd-kind-icon">test<wbr>Object<wbr>Clause</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#testoperatorclause" class="tsd-kind-icon">test<wbr>Operator<wbr>Clause</a> </li> <li class=" tsd-kind-function tsd-is-not-exported"> <a href="globals.html#testoperatorconstraint" class="tsd-kind-icon">test<wbr>Operator<wbr>Constraint</a> </li> <li class=" tsd-kind-object-literal tsd-is-not-exported"> <a href="globals.html#bson_types" class="tsd-kind-icon">BSON_<wbr>TYPES</a> </li> <li class=" tsd-kind-object-literal tsd-is-not-exported"> <a href="globals.html#groupoperators" class="tsd-kind-icon">group<wbr>Operators</a> </li> <li class=" tsd-kind-object-literal tsd-is-not-exported"> <a href="globals.html#modifiers" class="tsd-kind-icon">modifiers</a> </li> <li class=" tsd-kind-object-literal tsd-is-not-exported"> <a href="globals.html#stages" class="tsd-kind-icon">stages</a> </li> </ul> </nav> </div> </div> </div> <footer class="with-border-bottom"> <div class="container"> <h2>Legend</h2> <div class="tsd-legend-group"> <ul class="tsd-legend"> <li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li> <li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li> <li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li> <li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li> <li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li> <li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li> <li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li> <li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li> <li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li> <li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li> <li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li> <li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li> <li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li> <li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li> <li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li> <li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li> <li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li> <li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li> <li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li> <li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li> <li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li> <li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li> </ul> <ul class="tsd-legend"> <li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li> <li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li> </ul> </div> </div> </footer> <div class="container tsd-generator"> <p>Generated using <a href="http://typedoc.org/" target="_blank">TypeDoc</a></p> </div> <div class="overlay"></div> <script src="assets/js/main.js"></script> <script>if (location.protocol == 'file:') document.write('<script src="assets/js/search.js"><' + '/script>');</script> </body> </html>