Level DB - Quick Cheat Sheet

Aniruddha Chakrabarti
Aniruddha ChakrabartiGlobal Cloud Leader and Head of Architecture at EY
Aniruddha Chakrabarti
Associate Vice President and Chief Architect, Digital Practice, Mphasis
ani.c@outlook.com | Linkedin.com/in/aniruddhac | slideshare.net/aniruddha.chakrabarti | Twitter - anchakra
LevelDB Embedded Key Value Store
Quick Cheat sheet
Agenda
• What is LevelDB
• Why LevelDB was created
• LevelDB libraries and bindings
• LevelDB operations using Node
• Write data (put)
• Read data (get)
• Remove data (del)
• Batch Operations (batch)
• Iterating data (ReadStream)
• Storing and Retrieving JSON data
What is LevelDB
• LevelDB is a key value store, it stores data in disk. Highly optimized for fast read
write (specially writes - benchmark)
• Stores keys and values in arbitrary byte arrays, and data is sorted by key.
• LevelDB is typically used as embedded database (runs in the same process as
your code), but can be networked (by adding protocols such as http, tcp to your
process)
• LevelDB is not a key value database server like Redis or memcached. It’s a
database library similar to SQLite or Oracle Berkeley DB.
• Supported on Linux, Windows, OSX
• Has drivers and bindings for C++, Node, Python etc.
LevelDB is a light-weight, single-purpose library for persistence
with bindings to many platforms.
http://leveldb.org/
What is LevelDB
• Written by Google fellows Jeffrey Dean and Sanjay Ghemawat (authors of
MapReduce And BigTable)
• Inspired by BigTable - same general design as the BigTable tablet stack, but not
sharing any of the code
• Developed in early 2011
• Chrome IndexDB feature (HTML5 API) is built on top of LevelDB
• Similar storage libraries include Oracle Berkeley DB, SQLite, Kyoto Cabinet,
RocksDB etc.
LevelDB is a light-weight, single-purpose library for persistence
with bindings to many platforms.
http://leveldb.org/
Performance Benchmark
LevelDB outperforms both SQLite3 and TreeDB in sequential and random write operations and
sequential read operations. Kyoto Cabinet has the fastest random read operations
http://leveldb.googlecode.com/svn/trunk/doc/benchmark.html
LevelDB library and bindings
• LevelDown - Low-level Node.js LevelDB binding
• LevelUp – High level Node.js-style LevelDB wrapper. LevelUP aims to expose the
features of LevelDB in a Node.js-friendly way
• Rather than installing LevelDB and LevelUp separately you can install it as a
whole – npm install level
• We would be using LevelUp Node.js LevelDB wrapper for all our examples
• All operations in LevelUp are asynchronous although they don't necessarily
require a callback if you don't need to know when the operation was performed.
Installing LevelDB Node Bindings
Installation
• Install LevelUp Node Bindings (library) using npm (Node Package Manager) -
npm install level or
npm install level -- save (to update the dependency in project.json)
(LevelUp Node Bindings Location - https://github.com/Level/levelup)
Referencing the Node Library in code
• Reference the LevelUp Node library
var level = require('level');
• Create a db object by calling level() function passing the path where the data files would be stored.
db object contains all the methods required for interacting with LevelDB. Here the data files would
be stored in a subfolder called db relative to node file
var db = level('./db');
Write Data (put)
• Inserts/writes data into the store. Both the key and value can be arbitrary data objects.
• The Node API is asynchronous – put accepts key, value and a callback. Once the operation is
completed (success or error) the callback is called.
• If error occurs then the error object is passed as argument to the callback. The callback argument is
optional - if you don't provide the callback argument and an error occurs then the error is thrown, so
it’s better to provide the error argument.
var level = require('level');
var db = level('./db');
var key = "city", value = "Bangalore";
db.put(key, value, function(error){
if (error != null){
console.log(error);
}
else {
console.log('data saved successfully to disk');
}
});
Read Data (get)
• Reads/retrieves data from the store – the key for which data needs to be retrieved need to be
specified.
• Similar to get, put also works asynchronously. It accepts key and a callback. Once the operation is
completed (success or error) the callback is called, which accepts the value retrieved as parameter.
• If the key doesn't exist in the store then the callback will receive an error as its first argument. A not
found error object will be of type 'NotFoundError'
var key = "city", another_key = "student";
db.get(key, function(error, city){
console.log(city); // displays Bangalore
});
db.get(another_key, function(error, value){
if (error == null){
console.log(value);
}
else{
console.log(error.type + " - " + error.message);
} // displays NotFoundError - Key not found in database [student]
});
Remove Data (del)
• Removes data from the store permanently.
var key = "city";
db.del(key, function(error){
if (error != null){
console.log(error);
}
else {
console.log('data deleted successfully');
}
});
db.get(key, function(error, city){
console.log(city); // displays undefined
});
Batch Operations
• Batch operations could be used for very fast bulk-write operations
(both put and delete).
• Supports an array form and a chained form (similar to Fluent API)
• Array form
• db.batch(array, error callback)
• array argument should contain a list of operations to be executed sequentially, although as a
whole they are performed as an atomic operation inside LevelDB.
• Each operation is contained in an object having the following properties: type, key, value, where
the type is either 'put' or 'del'
• If key and value are defined but type is not, it will default to 'put'.
• Chained form
• batch(), when called with no arguments returns a Batch object which can be used to build, and
eventually commit, an atomic LevelDB batch operation.
• Depending on how it's used, it is possible to obtain greater performance when using the
chained form of batch() over the array form.
batch (array form)
var ops = [ // All operations of the batch are listed in an array
{type:'put', key:'city1', value:'Bangalore'}, // type of operation, key & value
{type:'put', key:'city2', value:'Kolkata'},
{type:'put', key:'city3', value:'Chennai'},
{type:'del', key:'city'},
]
db.batch(ops, function (error){
if (error != null){
console.log(error);
}
else {
console.log('batch operation successful');
}
})
batch (chained form)
• First line of code returns a Batch object which is then used to build all operations one by one
• Once it’s built, it’s eventually gets committed through write, which is an atomic LevelDB batch
operation.
db.batch() // returns a Batch object which is used to chain all operations
.del("city")
.put("city1","Bangalore")
.put("city2","Kolkata")
.put("city3","Chennai")
.write(function(){ // committing the batch operation
console.log('batch operation successful');
});
Iteration and ReadStream
• Get a ReadStream of the full database by calling the createReadStream() method – the returned
stream is a complete Node.js-style Readable Stream. data object have key and value property.
var stream = db.createReadStream()
stream.on('data', function (data) {
console.log('key=', data.key + ",value=" + data.value);
});
• Use the gt, lt and limit options to control the range of keys that are streamed.
var stream = db.createReadStream({limit:2})
KeyStream and ValueStream
• A KeyStream is a ReadStream where the 'data' events are simply the keys from the database – use
createKeyStream() method to get a KeyStream
• A ValueStream is a ReadStream where the 'data' events are simply the values from the database –
use createValueStream() method to get a ValueStream
Iterating through all keys
var keyStream = db.createKeyStream()
keyStream.on('data', function (data) {
console.log('key = ', data)
})
Iterating through all values
var valueStream = db.createValueStream()
valueStream.on('data', function (data) {
console.log('value = ', data)
})
Storing JSON objects
• JSON objects could be stored as value, apart from simple strings, numbers etc.
• To store JSON objects, set the valueEncoding options parameter to json while constructing the
db object.
• Multiple level of nested objects could be stored as value
var db = level('./dbJson', { valueEncoding : 'json' });
var employee = { name : "XYZ", age : 45, designation : "VP" };
db.put('employee', employee, function(error){
db.get('employee', function(error, employee){
console.log(employee.name); // Aniruddha
console.log(employee.age); // 45
console.log(employee.designation); // VP
});
});
Storing JSON objects (complex)
var db = level('./dbJson', { valueEncoding : 'json' });
var employee = { name : "XYZ", age : 45, designation : "VP" };
var employee = {
name : "XYZ",
age : 45,
designation : "VP",
skills : ["NoSQL","Management","Languages","Oracle"], // Array
address : { streetAddress:"123 M G Road", city: "Bangalore", country: "IN" } // Object
};
db.put('employee', employee, function(error){
db.get('employee', function(error, employee){
console.log(employee.name); // XYZ
console.log(employee.skills[0]); // NoSQL
console.log(employee.address.streetAddress + " - " + employee.address.city);
// 123 M G Road - Bangalore
});
});
1 of 17

More Related Content

What's hot

NfcNfc
NfcManish Bhagat
5K views26 slides
Wireless computingWireless computing
Wireless computingMukul Kumar
13.8K views14 slides
home networkinghome networking
home networkingSudeb Das
4.2K views11 slides
6G Technology6G Technology
6G TechnologyAkhil john
61.9K views26 slides
Introduction to zigbeeIntroduction to zigbee
Introduction to zigbeeAmit Dixit
1.9K views20 slides

What's hot(20)

Zigbee technologyZigbee technology
Zigbee technology
Srujana Aryasomayajula2K views
NfcNfc
Nfc
Manish Bhagat5K views
Wireless computingWireless computing
Wireless computing
Mukul Kumar13.8K views
home networkinghome networking
home networking
Sudeb Das4.2K views
6G Technology6G Technology
6G Technology
Akhil john61.9K views
Introduction to zigbeeIntroduction to zigbee
Introduction to zigbee
Amit Dixit1.9K views
NeuralinkNeuralink
Neuralink
898RakeshWaghmare1.6K views
zigbee technologyzigbee technology
zigbee technology
Deep Hundal3.5K views
Wi-Vi TechnologyWi-Vi Technology
Wi-Vi Technology
Anandhuas21.8K views
Wifi pptWifi ppt
Wifi ppt
Yousaf Sahota1.8K views
ppt on WIFIppt on WIFI
ppt on WIFI
Rohit Lakkabathini28.9K views
Mobile jammerMobile jammer
Mobile jammer
Avay Minni80.9K views
Iot office automationIot office automation
Iot office automation
Vivek Bhakta415 views
Neuralink technical seminarNeuralink technical seminar
Neuralink technical seminar
Rahul Agarwal27.8K views
5g technology5g technology
5g technology
Rohit Lanjewar1.4K views
Zigbee pptZigbee ppt
Zigbee ppt
Pranjul Rastogi3.3K views
ZIGBEE TECHNOLOGY pptZIGBEE TECHNOLOGY ppt
ZIGBEE TECHNOLOGY ppt
OECLIB Odisha Electronics Control Library8K views
Qr code power pointQr code power point
Qr code power point
Mary Papageorge9.4K views
Wibree pptWibree ppt
Wibree ppt
OECLIB Odisha Electronics Control Library3.3K views
ZigBee TechnologyZigBee Technology
ZigBee Technology
Nimi T2.5K views

Viewers also liked(20)

Google LevelDB Study DiscussGoogle LevelDB Study Discuss
Google LevelDB Study Discuss
everestsun9K views
LokijsLokijs
Lokijs
Joe Minichino511.3K views
LsmLsm
Lsm
Institute of Computing Technology, Chinese Academy of Sciences1.3K views
iOS + RailsiOS + Rails
iOS + Rails
Level UP935 views
Amazon EchoAmazon Echo
Amazon Echo
Raphaël CLERET140 views
Module01Module01
Module01
Sridhar P582 views
Multi-thematic spatial databasesMulti-thematic spatial databases
Multi-thematic spatial databases
Conor Mc Elhinney1.1K views
X query language referenceX query language reference
X query language reference
Steve Xu982 views
Module05Module05
Module05
Sridhar P486 views
Module03Module03
Module03
Sridhar P963 views
SQL Server 2008 Spatial Data - Getting StartedSQL Server 2008 Spatial Data - Getting Started
SQL Server 2008 Spatial Data - Getting Started
Integrated Network Strategies1.2K views
Css introductionCss introduction
Css introduction
Sridhar P1.7K views
Module07Module07
Module07
Sridhar P590 views

Similar to Level DB - Quick Cheat Sheet

Jdbc presentationJdbc presentation
Jdbc presentationnrjoshiee
500 views32 slides
Scala and SpringScala and Spring
Scala and SpringEberhard Wolff
9K views52 slides
jQuery ObjectsjQuery Objects
jQuery ObjectsSteve Wells
1.2K views20 slides
Raffaele RialdiRaffaele Rialdi
Raffaele RialdiCodeFest
207 views19 slides

Similar to Level DB - Quick Cheat Sheet(20)

Jdbc presentationJdbc presentation
Jdbc presentation
nrjoshiee500 views
Scala and SpringScala and Spring
Scala and Spring
Eberhard Wolff9K views
jQuery ObjectsjQuery Objects
jQuery Objects
Steve Wells1.2K views
Raffaele RialdiRaffaele Rialdi
Raffaele Rialdi
CodeFest207 views
Couchbas for dummiesCouchbas for dummies
Couchbas for dummies
Qureshi Tehmina628 views
Wider than railsWider than rails
Wider than rails
Alexey Nayden1.8K views
Getting Input from UserGetting Input from User
Getting Input from User
Lovely Professional University16 views
Unit-2 Getting Input from User.pptxUnit-2 Getting Input from User.pptx
Unit-2 Getting Input from User.pptx
Lovely Professional University85 views
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
Richard Lee2K views
UnqliteUnqlite
Unqlite
Paul Myeongchan Kim2.6K views
cb streams - gavin pickincb streams - gavin pickin
cb streams - gavin pickin
Ortus Solutions, Corp144 views
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS Backend
Laurent Cerveau1K views
CBStreams - Java Streams for ColdFusion (CFML)CBStreams - Java Streams for ColdFusion (CFML)
CBStreams - Java Streams for ColdFusion (CFML)
Ortus Solutions, Corp905 views

More from Aniruddha Chakrabarti(20)

Pinecone Vector Database.pdfPinecone Vector Database.pdf
Pinecone Vector Database.pdf
Aniruddha Chakrabarti160 views
Mphasis-Annual-Report-2018.pdfMphasis-Annual-Report-2018.pdf
Mphasis-Annual-Report-2018.pdf
Aniruddha Chakrabarti28 views
NLP using JavaScript Natural LibraryNLP using JavaScript Natural Library
NLP using JavaScript Natural Library
Aniruddha Chakrabarti2.4K views
Dart programming languageDart programming language
Dart programming language
Aniruddha Chakrabarti5.4K views
Third era of computingThird era of computing
Third era of computing
Aniruddha Chakrabarti643 views
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
Aniruddha Chakrabarti7.1K views
Amazon alexa - building custom skillsAmazon alexa - building custom skills
Amazon alexa - building custom skills
Aniruddha Chakrabarti16.4K views
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflows
Aniruddha Chakrabarti2.2K views
Future of .NET - .NET on Non Windows PlatformsFuture of .NET - .NET on Non Windows Platforms
Future of .NET - .NET on Non Windows Platforms
Aniruddha Chakrabarti759 views
CoAP - Web Protocol for IoTCoAP - Web Protocol for IoT
CoAP - Web Protocol for IoT
Aniruddha Chakrabarti8.3K views
Groovy Programming LanguageGroovy Programming Language
Groovy Programming Language
Aniruddha Chakrabarti1.7K views
LispLisp
Lisp
Aniruddha Chakrabarti9.4K views
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
Aniruddha Chakrabarti767 views
memcached Distributed Cachememcached Distributed Cache
memcached Distributed Cache
Aniruddha Chakrabarti1K views
Redis and it's data typesRedis and it's data types
Redis and it's data types
Aniruddha Chakrabarti2.5K views
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
Aniruddha Chakrabarti854 views
TypeScript OverviewTypeScript Overview
TypeScript Overview
Aniruddha Chakrabarti5.9K views

Recently uploaded(20)

[2023] Putting the R! in R&D.pdf[2023] Putting the R! in R&D.pdf
[2023] Putting the R! in R&D.pdf
Eleanor McHugh34 views
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman152 views
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)
CSUC - Consorci de Serveis Universitaris de Catalunya51 views
CXL at OCPCXL at OCP
CXL at OCP
CXL Forum183 views
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
METHOD AND SYSTEM FOR PREDICTING OPTIMAL LOAD FOR WHICH THE YIELD IS MAXIMUM ...
Prity Khastgir IPR Strategic India Patent Attorney Amplify Innovation23 views
Green Leaf Consulting: Capabilities DeckGreen Leaf Consulting: Capabilities Deck
Green Leaf Consulting: Capabilities Deck
GreenLeafConsulting170 views

Level DB - Quick Cheat Sheet

  • 1. Aniruddha Chakrabarti Associate Vice President and Chief Architect, Digital Practice, Mphasis ani.c@outlook.com | Linkedin.com/in/aniruddhac | slideshare.net/aniruddha.chakrabarti | Twitter - anchakra LevelDB Embedded Key Value Store Quick Cheat sheet
  • 2. Agenda • What is LevelDB • Why LevelDB was created • LevelDB libraries and bindings • LevelDB operations using Node • Write data (put) • Read data (get) • Remove data (del) • Batch Operations (batch) • Iterating data (ReadStream) • Storing and Retrieving JSON data
  • 3. What is LevelDB • LevelDB is a key value store, it stores data in disk. Highly optimized for fast read write (specially writes - benchmark) • Stores keys and values in arbitrary byte arrays, and data is sorted by key. • LevelDB is typically used as embedded database (runs in the same process as your code), but can be networked (by adding protocols such as http, tcp to your process) • LevelDB is not a key value database server like Redis or memcached. It’s a database library similar to SQLite or Oracle Berkeley DB. • Supported on Linux, Windows, OSX • Has drivers and bindings for C++, Node, Python etc. LevelDB is a light-weight, single-purpose library for persistence with bindings to many platforms. http://leveldb.org/
  • 4. What is LevelDB • Written by Google fellows Jeffrey Dean and Sanjay Ghemawat (authors of MapReduce And BigTable) • Inspired by BigTable - same general design as the BigTable tablet stack, but not sharing any of the code • Developed in early 2011 • Chrome IndexDB feature (HTML5 API) is built on top of LevelDB • Similar storage libraries include Oracle Berkeley DB, SQLite, Kyoto Cabinet, RocksDB etc. LevelDB is a light-weight, single-purpose library for persistence with bindings to many platforms. http://leveldb.org/
  • 5. Performance Benchmark LevelDB outperforms both SQLite3 and TreeDB in sequential and random write operations and sequential read operations. Kyoto Cabinet has the fastest random read operations http://leveldb.googlecode.com/svn/trunk/doc/benchmark.html
  • 6. LevelDB library and bindings • LevelDown - Low-level Node.js LevelDB binding • LevelUp – High level Node.js-style LevelDB wrapper. LevelUP aims to expose the features of LevelDB in a Node.js-friendly way • Rather than installing LevelDB and LevelUp separately you can install it as a whole – npm install level • We would be using LevelUp Node.js LevelDB wrapper for all our examples • All operations in LevelUp are asynchronous although they don't necessarily require a callback if you don't need to know when the operation was performed.
  • 7. Installing LevelDB Node Bindings Installation • Install LevelUp Node Bindings (library) using npm (Node Package Manager) - npm install level or npm install level -- save (to update the dependency in project.json) (LevelUp Node Bindings Location - https://github.com/Level/levelup) Referencing the Node Library in code • Reference the LevelUp Node library var level = require('level'); • Create a db object by calling level() function passing the path where the data files would be stored. db object contains all the methods required for interacting with LevelDB. Here the data files would be stored in a subfolder called db relative to node file var db = level('./db');
  • 8. Write Data (put) • Inserts/writes data into the store. Both the key and value can be arbitrary data objects. • The Node API is asynchronous – put accepts key, value and a callback. Once the operation is completed (success or error) the callback is called. • If error occurs then the error object is passed as argument to the callback. The callback argument is optional - if you don't provide the callback argument and an error occurs then the error is thrown, so it’s better to provide the error argument. var level = require('level'); var db = level('./db'); var key = "city", value = "Bangalore"; db.put(key, value, function(error){ if (error != null){ console.log(error); } else { console.log('data saved successfully to disk'); } });
  • 9. Read Data (get) • Reads/retrieves data from the store – the key for which data needs to be retrieved need to be specified. • Similar to get, put also works asynchronously. It accepts key and a callback. Once the operation is completed (success or error) the callback is called, which accepts the value retrieved as parameter. • If the key doesn't exist in the store then the callback will receive an error as its first argument. A not found error object will be of type 'NotFoundError' var key = "city", another_key = "student"; db.get(key, function(error, city){ console.log(city); // displays Bangalore }); db.get(another_key, function(error, value){ if (error == null){ console.log(value); } else{ console.log(error.type + " - " + error.message); } // displays NotFoundError - Key not found in database [student] });
  • 10. Remove Data (del) • Removes data from the store permanently. var key = "city"; db.del(key, function(error){ if (error != null){ console.log(error); } else { console.log('data deleted successfully'); } }); db.get(key, function(error, city){ console.log(city); // displays undefined });
  • 11. Batch Operations • Batch operations could be used for very fast bulk-write operations (both put and delete). • Supports an array form and a chained form (similar to Fluent API) • Array form • db.batch(array, error callback) • array argument should contain a list of operations to be executed sequentially, although as a whole they are performed as an atomic operation inside LevelDB. • Each operation is contained in an object having the following properties: type, key, value, where the type is either 'put' or 'del' • If key and value are defined but type is not, it will default to 'put'. • Chained form • batch(), when called with no arguments returns a Batch object which can be used to build, and eventually commit, an atomic LevelDB batch operation. • Depending on how it's used, it is possible to obtain greater performance when using the chained form of batch() over the array form.
  • 12. batch (array form) var ops = [ // All operations of the batch are listed in an array {type:'put', key:'city1', value:'Bangalore'}, // type of operation, key & value {type:'put', key:'city2', value:'Kolkata'}, {type:'put', key:'city3', value:'Chennai'}, {type:'del', key:'city'}, ] db.batch(ops, function (error){ if (error != null){ console.log(error); } else { console.log('batch operation successful'); } })
  • 13. batch (chained form) • First line of code returns a Batch object which is then used to build all operations one by one • Once it’s built, it’s eventually gets committed through write, which is an atomic LevelDB batch operation. db.batch() // returns a Batch object which is used to chain all operations .del("city") .put("city1","Bangalore") .put("city2","Kolkata") .put("city3","Chennai") .write(function(){ // committing the batch operation console.log('batch operation successful'); });
  • 14. Iteration and ReadStream • Get a ReadStream of the full database by calling the createReadStream() method – the returned stream is a complete Node.js-style Readable Stream. data object have key and value property. var stream = db.createReadStream() stream.on('data', function (data) { console.log('key=', data.key + ",value=" + data.value); }); • Use the gt, lt and limit options to control the range of keys that are streamed. var stream = db.createReadStream({limit:2})
  • 15. KeyStream and ValueStream • A KeyStream is a ReadStream where the 'data' events are simply the keys from the database – use createKeyStream() method to get a KeyStream • A ValueStream is a ReadStream where the 'data' events are simply the values from the database – use createValueStream() method to get a ValueStream Iterating through all keys var keyStream = db.createKeyStream() keyStream.on('data', function (data) { console.log('key = ', data) }) Iterating through all values var valueStream = db.createValueStream() valueStream.on('data', function (data) { console.log('value = ', data) })
  • 16. Storing JSON objects • JSON objects could be stored as value, apart from simple strings, numbers etc. • To store JSON objects, set the valueEncoding options parameter to json while constructing the db object. • Multiple level of nested objects could be stored as value var db = level('./dbJson', { valueEncoding : 'json' }); var employee = { name : "XYZ", age : 45, designation : "VP" }; db.put('employee', employee, function(error){ db.get('employee', function(error, employee){ console.log(employee.name); // Aniruddha console.log(employee.age); // 45 console.log(employee.designation); // VP }); });
  • 17. Storing JSON objects (complex) var db = level('./dbJson', { valueEncoding : 'json' }); var employee = { name : "XYZ", age : 45, designation : "VP" }; var employee = { name : "XYZ", age : 45, designation : "VP", skills : ["NoSQL","Management","Languages","Oracle"], // Array address : { streetAddress:"123 M G Road", city: "Bangalore", country: "IN" } // Object }; db.put('employee', employee, function(error){ db.get('employee', function(error, employee){ console.log(employee.name); // XYZ console.log(employee.skills[0]); // NoSQL console.log(employee.address.streetAddress + " - " + employee.address.city); // 123 M G Road - Bangalore }); });