Bongo.js is a JavaScript library for storing and querying structured data on the browser. Lots of it.
It is built on IndexedDB.
It is tested in Chrome 27, Chrome 29, Firefox 22, and Internet Explorer 10.
- Insert, save, remove, find, findOne
- Comparison query operators ($all, $lt, $lte, $gt, $gte, $in, $nin)
- Mongo-esque key generator (on _id)
- Pick, limit, skip
- Automatic versioning and database upgrades
- Custom filters
- 11k
Use Bower:
bower install bongo.js
And include the file in your app:
<script src='/components/bongo.js/dist/bongo.min.js'></script>
You can also download the compressed, production version or the uncompressed, development version.
bongo.db({
name: 'acme',
collections: ["users"]
});
bongo.db('acme').collection('users').insert({
name: "John Doe",
email: "john@domain.com"
},function(error,id) {
if(!error) {
// success
}
}
});
bongo.db('acme').collection('users').save({
_id: "[key]", //optional
name: "Jane Doe",
email: "jane@domain.com",
pets: 3
});
bongo.db('acme').collection('users').get("[key]", function(error,data) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
name: "John Doe"
}).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
name: /john/i
}).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
pets: {$gt: 2}
}).toArray(function(error,results) {
if(!error) {
//success
}
});
$all, $lt, $lte, $gt, $gte, $in, $nin are supported.
bongo.db('acme').collection('users').findOne({
name: "John Doe"
}),function(error,record) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').filter(function(doc) {
return doc.age > 30;
}).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
age: {$gt: 30}
},{
name: 1,
email: 1
}).toArray(function(error,results) {
if(!error) {
//success
}
});
or
bongo.db('acme').collection('users').find({
age: {$gt: 30}
}).pick(['name','email']).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
age: {$gt: 30}
}).limit(5).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').find({
age: {$gt: 30}
}).skip(5).limit(5).toArray(function(error,results) {
if(!error) {
//success
}
});
bongo.db('acme').collection('users').remove({
email: "john@domain.com"
}, function(error, data) {
if(!error) {
//success
}
})
Or just use the key:
bongo.db('acme').collection('users').remove("[key]", function(error, data) {
if(!error) {
//success
}
});
bongo.delete(function(error) {
if(!error) {
// Success
}
});
if(bongo.supported) {
// Woo hoo!
}
- After many(?) database version upgrades, sometimes Chrome needs to be restarted.
- Redefining the same database multiple times in the same pageload is problematic.
MIT. Forking is form of flattery.
- Introduction to Bongo.js (slides)
- aaronpowell/db.js
- maxogden/level.js
- jensarps/IDBWrapper
- axemclion/IndexedDB
- grgrssll/IndexedDB
- ironfroggy/plasmid
- lukasolson/Local-DB
- [malucomarinero/johodb] (http://malucomarinero.bitbucket.org/johodb/)
- linq2indexeddb
- mozilla-b2g/gaia/async_storage.js
- superfeedr/indexeddb-backbonejs-adapter
- ytkyaw/ydn-db (adapter)
- brianleroux/lawnchair (adapter)
- daleharvey/pouchdb (adapter)
- facebook/IndexedDB-polyfill (polyfill)
- axemclion/IndexedDBShim (polyfill)
- [Parashuram's IndexedDB Experiments] (http://nparashuram.com/IndexedDB/)
- The ObjectStore Database System, by Charles Lamb, Gordon Landis, Jack Orenstein, and Dan Weinreb (PDF)
- [louischatriot/nedb]((https://github.com/louischatriot/nedb)