Lokijs is a memory database that puts performance considerations in the first place.
Lokijs supports indexing and faster document access, performing very well (nearly 500,000 ops/seconds). Its built-in Dynamicview classes can be used for indexing of subsets of data, even faster performance.
* Read this article to see the performance of Lokijs.
Lokijs supports collections (datasets), like MongoDB, and saves data to disk in JSON format, so your data is portable.
Lokijs can be run on the Node.js side and the browser side.
JavaScript is a simple, universal language, so it's very easy and efficient to develop JavaScript databases. If your MongoDB is not retired, you may find Lokijs a better solution in the following situations:
1. Mobile applications-especially HTML applications. (Cordova, Phonegap)
2.node.js built-in data storage for small to medium application design
3. Applications built into the desktop (Node Webkit)
Lokijs is supporting stand-alone servers and can be accessed using HTTP/TCP clients.
Choose the paradigm you like best
The Lokijs function fully utilizes the power of JavaScript.
If functional programming is your preferred style, you will certainly prefer to use views to query the data.
You can also use your preferred MongoDB Shell to query text objects.
Quick Start
Installation
Lokijs can be installed in NPM and Bower. Run:
Copy Code code as follows:
Or
Copy Code code as follows:
Use
To create a database:
Copy Code code as follows:
var db = new Loki (' Loki.json ')
Pass in the JSON file where you need to save the data
To create a dataset:
Copy Code code as follows:
var children = db.addcollection (' Children ')
To insert a document:
Copy Code code as follows:
Children.insert ({name: ' Sleipnir ', legs:8})
Children.insert ({name: ' Jormungandr ', legs:0})
Children.insert ({name: ' Hel ', legs:2})
To get a document:
Copy Code code as follows:
Children.get (1); Returns Sleipnir
Children.find ({' name ': ' Sleipnir '})
Children.find ({legs: {' $gt ': 2}})
To create a dynamic view:
Copy Code code as follows:
var legs = children.adddynamicview (' legs ');
Legs.applyfind ({legs: {' $gt ': 2})
Legs.applysimplesort (' legs ');
Legs.data ();
MapReduce (Data aggregation):
Copy Code code as follows:
Children.mapreduce (
function (obj) {return obj.legs;},
Function (array) {
var sum = 0;
for (Var i=0 i < Array.Length; i++) {
Sum + + array[i];
}
Return (sum/array.length). toFixed (2);
});