Quick Start Guide¶
- Quick Start Guide
- Overview
- Prerequisites
- Get the Script
- Create or Load a Database
- Create a Collection and Insert Data
- Read, Update, and Delete
- Persist Changes
Overview¶
This guide walks through creating a database, adding data, and running basic queries using the public JsonDbApp API. It targets Apps Script library consumers and mirrors the MongoDB-style collection interface.
Prerequisites¶
- Google Apps Script project with the JsonDbApp library added.
- Drive API enabled for the Google Cloud project that backs your Apps Script deployment.
Get the Script¶
Link it as a library to your chosen GAS project.
Create or Load a Database¶
Use the public wrappers exposed by the library identifier (typically JsonDbApp). For first-time setup, create and initialise the MasterIndex. For subsequent use, load the existing database.
const config = new DatabaseConfig({
rootFolderId: 'YOUR_DRIVE_FOLDER_ID',
autoCreateCollections: true
});
// First-time setup
const db = JsonDbApp.createAndInitialiseDatabase(config);
// Existing database
// const db = JsonDbApp.loadDatabase(config);
Create a Collection and Insert Data¶
const users = db.createCollection('users');
const result = users.insertOne({
name: 'Ada',
role: 'Engineer',
age: 36
});
const userId = result.insertedId;
Read, Update, and Delete¶
// Read
const ada = users.findOne({ _id: userId });
const engineers = users.find({ role: 'Engineer' });
// Update
users.updateOne({ _id: userId }, { $set: { role: 'Lead Engineer' } });
// Delete
users.deleteOne({ _id: userId });
Persist Changes¶
Write operations mark collections as dirty. Call save() after a batch of changes so data is written to Drive.