Quickstart
Open Nimbus in your dashboard, create a project and copy its key. Then add this to any page:
<script src="https://buzzcloud.win/nimbus/sdk.js"></script>
<script>
const app = Nimbus.init({ key: 'nk_your_project_key' });
const db = app.db();
db.collection('messages').add({ text: 'Hello!', at: Nimbus.serverTimestamp() });
</script>
Database
Data lives in collections of documents. A document is a JSON object up to 256 KB with an ID. Subcollections hang off documents: rooms/lobby/messages.
// add with a generated ID
const ref = await db.collection('posts').add({ title: 'Hi', likes: 0 });
// write with your own ID (replaces, or merges with { merge: true })
await db.doc('profiles/ada').set({ name: 'Ada' });
await db.doc('profiles/ada').set({ bio: 'Engineer' }, { merge: true });
// change some fields
await db.doc('posts/' + ref.id).update({ likes: Nimbus.increment(1), 'meta.edited': true });
// read
const snap = await db.doc('profiles/ada').get();
if (snap.exists) console.log(snap.data());
// query
const top = await db.collection('posts').where('likes', '>=', 10).orderBy('likes', 'desc').limit(20).get();
top.forEach(d => console.log(d.id, d.data()));
// delete
await db.doc('posts/' + ref.id).delete();
Query operators
== != < <= > >= in not-in array-contains. Order by any field, or by __created, __updated or __id. Up to 500 results per query; use .offset(n) to page.
Special values
| Value | Does |
|---|---|
Nimbus.serverTimestamp() | The server’s time in milliseconds |
Nimbus.increment(n) | Adds n to a number (atomic) |
Nimbus.arrayUnion(...v) | Adds items to an array if missing |
Nimbus.arrayRemove(...v) | Removes items from an array |
Nimbus.deleteField() | Removes a field in update / merge |
Batches
const b = db.batch();
b.set(db.doc('scores/ada'), { points: 10 });
b.delete(db.doc('scores/bob'));
await b.commit(); // all or nothing, up to 100 writes
Live updates
Listen to a document or a query. Your callback runs right away and again whenever anything changes — from any visitor.
const stop = db.collection('messages').orderBy('at').limit(100).onSnapshot(snap => {
list.innerHTML = snap.docs.map(d => `<li>${d.data().text}</li>`).join('');
}, err => console.error(err));
// later
stop();
Sign-in
Each project has its own users. Turn sign-in methods on or off in the console.
const auth = app.auth();
auth.onAuthChange(user => {
console.log(user ? 'Signed in as ' + (user.name || user.email) : 'Signed out');
});
await auth.signUp('[email protected]', 'a long password', 'Ada');
await auth.signIn('[email protected]', 'a long password');
await auth.signInWithBuzzCloud(); // opens a small window
await auth.signOut();
auth.currentUser; // { uid, email, name, provider } or null
Also: auth.updateProfile({ name }), auth.changePassword(current, next), auth.deleteAccount().
Storage
const storage = app.storage();
const file = input.files[0];
const up = await storage.upload('avatars/' + auth.currentUser.uid + '.png', file);
img.src = up.url; // a permanent link
const files = await storage.list('avatars/');
await storage.delete('avatars/old.png');
Security rules
Rules decide who can read and write. Edit them in the console — start from a preset and adjust. A rule is true, false, or an expression.
{
"database": {
"messages": { "read": true, "create": "auth != null", "update": "auth.uid == owner", "delete": "auth.uid == owner" },
"rooms/{room}/messages": { "read": "auth != null", "write": "auth != null" },
"*": { "read": false, "write": false }
},
"storage": { "read": true, "write": "auth != null" }
}
| In rules | Means |
|---|---|
auth | The signed-in visitor (auth.uid, auth.email, auth.name), or null |
owner | The uid of whoever created the document or file |
doc | The document as stored now (null when creating) |
data | The document as it would be after the write |
id, {room} | The document ID, and any {names} from the collection pattern |
path, size, contentType | Storage only: the file being written |
now | Current time in milliseconds |
Operators: == != < <= > >= in ! && || and parentheses; .length works on strings and arrays. write covers create, update and delete. If no rule matches, the answer is no. Queries quietly leave out documents a visitor isn’t allowed to read.
Example: "create": "auth != null && data.text.length <= 500"
Limits
| Per project | |
|---|---|
| Documents | 50,000 |
| Document size | 256 KB |
| Storage | 500 MB, files up to 25 MB |
| Visitor accounts | 20,000 |
| Live listeners | 100 per browser tab |
| Projects | 10 per BuzzCloud account |
Nimbus follows the BuzzCloud Terms and Acceptable Use Policy.