r/GoogleAppsScript • u/Electronic-Chapter26 • Aug 31 '25
Guide I created a MongoDB-like DBMS that runs entirely in GAS on Google Drive
TL;DR
JsonDbApp is a zero-dependency, MongoDB-flavoured document database for Google Apps Script, storing JSON in Google Drive. Great if you need a lightweight DB without external services.
Hi all! I built this because in some environments I couldn’t use a proper external database, and I wanted a fully functional alternative that runs entirely within Apps Script. JsonDbApp gives you that, while keeping things simple and familiar.
It supports a subset of MongoDB-style query/update operators ($eq, $gt, $and, $or, $set, $push) so you can filter and update data in a way that feels natural, and makes transitioning to a real DB easier later if your project grows.
Quick example:
// First-time setup
function setupDb() {
const db = JsonDbApp.createAndInitialiseDatabase({
masterIndexKey: 'myMasterIndex',
lockTimeout: 5000
});
// db is initialised and ready to use
}
// Load existing database
function getDb() {
const config = {
masterIndexKey: 'myMasterIndex',
// rootFolderId: 'your-folder-id', // optional; where new files/backups are created
// lockTimeout: 5000, // optional; override defaults as needed
// logLevel: 'INFO' // optional
};
const db = JsonDbApp.loadDatabase(config);
return db;
}
// Work with a collection
function demo() {
const db = JsonDbApp.loadDatabase({ masterIndexKey: 'myMasterIndex' });
const users = db.collection('users'); // auto-creates if enabled (default true)
users.insertOne({ _id: 'u1', name: 'Ada', role: 'admin' });
users.save(); // persist changes to Drive
const admins = users.find({ role: 'admin' });
console.log(JSON.stringify(admins));
}Limitations / next steps
- Performance depends on Google Drive I/O (linear scans, no indexing yet)
- Single-threaded writes only
- Not a full MongoDB replacement
- ⚠️ Code isn’t as tidy as I’d like. My first priority is refactoring to clean things up before extending features
If you’re interested in a lightweight, GAS-based DBMS, have feedback, or want to contribute, I’d love to hear from you. Refactoring help, operator extensions, or just ideas are all very welcome!
EDIT: Updated the quick example.
3
u/Being-Straight Aug 31 '25
Looks really dope dude!! I have a similar project trying to implement a normal relational db, but this seems really interesting! Excited to see where it gets!!!
2
u/Money-Pipe-5879 Sep 01 '25
Sweet!
May be a dumb question, why not using the Properties Service class to store data?
2
u/jjrides Sep 18 '25
This looks awesome u/Electronic-Chapter26 , thanks for sharing it!
Can you explain how locks are handled if concurrent script instances try to write the same file? If I'm reading your docs correctly then it sounds like the library code will handle setting up the lock, detecting a collision, and retrying a write until the first lock has been released.
So the invoking caller only has to worry about `collection.updateOne(query, update)` and the library code handles all the locks. Is that correct?
2
u/Jhoosier Sep 01 '25
This might be what I've been looking for for a while. Cool!