简体   繁体   中英

How do I permanently delete a collection in forerunnerdb?

I tried using remove() for each collection item in a for loop, and that appeared to be successful. However, the items are still in the collection. I will be happy to just remove the collection entirely if there is a way to do it via JavaScript.

Here is the returned object after each remove() - in console.log:

 deleted ID1[object Object]
 dbsetup.js:304 1 - deleted ID2[object Object]
 dbsetup.js:304 2 - deleted ID1ee7978aa5ddc20[object Object]
 dbsetup.js:304 3 - deleted ID2899af1e797ff00[object Object]
 dbsetup.js:304 4 - deleted ID2234cd96dac8380[object Object]
 dbsetup.js:304 5 - deleted ID348a5bcd5f0f600[object Object]
 dbsetup.js:304 6 - deleted ID490930bb2589c80[object Object]

And here is my function that uses forerunner's remove():

function removeAllGames() {
    var gameArray = games.find();
    var gameID;
    var deletedObject;
    var len = gameArray.length;

   for (var i=0;i<len;i++) {
       gameID = gameArray[i]._id;

       deletedObject = games.remove({
            _id: gameID
       });
       console.log(i + " - " + "deleted ID" + gameID + deletedObject);
    }
}

I'll report my progress - thanks for your help!

ForerunnerDB operates in memory. This means that if you load data from persistent storage and then modify it through ForerunnerDB's CRUD methods (insert, update, remove) you are modifying the in-memory data.

If you then want that new version of the data to overwrite the currently persisted data you need to call .save().

Just to be clear on the usage, collection.remove() will remove all documents from the collection, but it will not persist that removal to storage until you call .save() afterwards.

Persistent storage is a plugin to ForerunnerDB rather than built-in to the core since the primary use of ForerunnerDB is as an in-memory store for manipulating JSON data and some users may not want persistence. That is why you have to call .load() and .save() to load data from persistent storage and save data there respectively.

The CRUD calls like insert() and remove() are talking to ForerunnerDB's core, while the load() and save() methods are talking to the persistence plugin.

(Source: I wrote ForerunnerDB and all the plugins).

I figured it out! I need to use the save() function after the remove() function. After doing this, the items where permanently gone from the collection. I still need to figure out how to delete the collection itself, but for now this is enough to get the job done.

I recommend looking at the forerunnerdb tutorials, and not just relying on the documentation on github (like I did). The tutorials give working examples on how to save properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM