Hi guys!
I've been using ShareJS for a while and am glad to see the continual progress being made. 😃
But this question has me stumped. I've probably spent at least four hours trying to solve it this afternoon to no avail.
I'm switching over from a previous setup in a project I'm working on where I used ShareJS 0.7 and livedb-mongo, transitioning to just ShareDB. Before, I would delete documents off the database via:
var db = require('livedb-mongo')(configdb.url, { safe : true });
var backend = livedb.client(db);
backend.submit(author, title, {del: true}, function(err) {
if (err) {
console.log("There was an error: " + err);
} else {
console.log("Yay! BAI: " + author + ", " + title);
}
Say I executed the above. When I would try to reconnect my textarea using whatever I'd passed in as "author" and "title," it would point to a blank (now deleted) document. Hurray!
After reading through the readme, I gathered that the way to do this in ShareDB is via this but maybe I'm completely wrong:
var db = require('sharedb-mongo')(dbConfig.aloft);
var backend = ShareDB({db: db});
var connection = backend.connect();
var doc = connection.get(author, title);
if (doc) { // If there actually is a match with author & title, then proceed.
doc.del(function (err) {
if (err) {
console.log('there was an error: ' + err);
} else {
console.log('deleted successfully.');
}
})
}
I keep getting "there was an error: Error: Document does not exist" and when I reconnect to the doc with whatever I assigned to "author" and "title," everything is obviously still there.
So I must not be invoking connection.get() correctly to find the matching document before actually executing the del command? Also, in the readme it says correct syntax for del is doc.del([options][, function(err) {...}]) takes options as the first parameter, but I don't know what "options" should be in this case. There isn't any explanation as to what "options" there are or how to correctly define/format them for .del().
Is .del() used to delete operations or is it used to delete entire document objects?
All I'm trying to do is delete the contents of a document so that when you reconnect to it, it's blank rather than what was last written to it.
I hope this makes sense. Apologies if this is a really basic question. I can't seem to get what the readme is telling me no matter how many times I read it. ☹️
Thanks!
-S