https://github.com/axfab/tiny-db
Small document database. Create a store of JSON documents
https://github.com/axfab/tiny-db
Last synced: 7 months ago
JSON representation
Small document database. Create a store of JSON documents
- Host: GitHub
- URL: https://github.com/axfab/tiny-db
- Owner: AxFab
- Created: 2015-04-02T12:40:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-04-03T14:07:01.000Z (over 10 years ago)
- Last Synced: 2025-02-25T02:39:43.189Z (8 months ago)
- Language: JavaScript
- Size: 115 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tiny DB
Tiny DB is a JSON document store database.
The API is based on MongoDB, however it may not stay compatible forever.
## Getting started
The configuration is prety straitforward, this is one of the most important aspect of TinyDB:
Easy to install, easy to use.
The client will try to connect to the service using a single url parameter.
To start either choose null for an in-memory database or a local directory to use as storage.
For more option refer to the section named scalling service.
I will present here the most useful function that you need to
start using your new database.
### Connection
```
// Connection URL
var url = null; // Use in-memory database
// Use connect method to connect to db service
ClientDb.connect(url, function(err, db) {
// ...
})
```
### Insertion
Inserts a document or documents into a collection.
The method take either a simple object or an array of object.
The second argument can be an option object with some settings, and the last
argument is a callback to call at the end of the query.
```
// Get the documents collection
var collection = db.collection('documents')
// Insert some documents
collection.insert([
{a : 1}, {a : 2}, {a : 3}
], function (err, res) {
// ...
})
```
Options are:
- `writeConcern` : See Safe Writes.
- `ordered` : Should the items inserted in given order or in parralel.
### Update
```
// Get the documents collection
var collection = db.collection('documents')
// Insert some documents
collection.update(
{ a : 2 },
{ $set: { b : 1 } },
function (err, res) {
// ...
})
```
### Delete
```
// Get the documents collection
var collection = db.collection('documents')
// Insert some documents
collection.update(
{ a : 3 },
function (err, res) {
// ...
})
```
### Find
```
// Get the documents collection
var collection = db.collection('documents')
// Insert some documents
collection.find({}).toArray(function (err, docs) {
// ...
})
```
## Scalling service
> Not implemented