Collections
Documentation of the Collection class in abc.db
Last updated
Was this helpful?
Documentation of the Collection class in abc.db
Last updated
Was this helpful?
Collections in abc.db represent those inside mongo db, and every collection you make in your code will be a new one inside your mongo db. The collection variable is stored inside the and in these examples, I will be using the same variable to call them from as the examples in the documentation.
To use the collection, call it from the Main class:
All methods are promises currently, meaning they must be awaited ()
These methods are used to insert of modify data inside the database. They all return the new value of the key
To set a value to something, you use the set method and provide a key and a value to set.
All the data modifying methods (set, add, subtract, push) and the get/find method support dot notation, similar to quick.db e.g.
To add and subtract from numbers, you use the subtract method. If the value is not a number or does not exist, then the value is set to add/subtract from 0.
The push method pushes an item into an array, meaning it is put at the end. If the value is not an array, it will be made one with the current value being first, the second value being next.
The get/find and has methods work similarly, except one returns the value, the other returns whether or not it exists. In both, if the key does not have a value, it will return false. The find and get method are exactly the same.
The getAll method returns all the documents inside the database as an array of objects containing a key and a value
The delete method removes a document from the database, and returns a boolean of whether or not it could be deleted.
Warning, if you execute this method, as it suggests, every document inside your collection will be deleted. Only run this if you are absolutely sure that you want all of your documents deleted.
The delete all method deletes everything inside the collection, meaning nothing can be recovered
The for each method executes something for every entry in the database
The migrate from quick.db method moves everything over from quick.db For more info