As @jcasman and I have been actively experimenting with Termux and Node/Express, I wanted to use MongoDB to start storing information needed for an image gallery.
Although I couldn’t get MongoDB to run inside the THETA, I did succeed in using NeDB to store and retrieve documents with Node. As the API is compatible with MongoDB, it seems like a good choice for experimentation.
const fs = require('fs');
const Datastore = require('nedb');
const images = new Datastore({ filename: 'images.db' });
const cameraPictureDir = '/sdcard/DCIM/100RICOH/'
images.loadDatabase();
function loadAll() {
fs.readdir(cameraPictureDir, (fileErr, items)=> {
if (!fileErr) {
console.log("About to insert these items \n" + items);
items.forEach(item => {
const image = {
title: 'Beautiful title for ' + item,
filename: item
}
images.insert(image, (err, doc)=> {
if (!err) {
console.log('Inserted', doc.filename, 'with ID', doc._id);
} else {
console.log(err);
}
});
})
} else {
console.log(fileErr);
}
});
}
function findAll() {
images.find({}, (err, doc)=> {
if (!err) {
console.log(doc);
} else {
console.log(err);
}
});
}
// loadAll();
// images.remove({_id: 'lZaB4KIijYsmIKde'});
findAll();
Example output of running the findAll()
function.