Removing documents

remove removes all Documents (matching the query) but can be limited in the amount of removals. It will return the amount of objects that have been removed.

try collection.remove() // returns 5

The above example will remove all Documents.

You can specify requirements for the documents that will be removed by adding a matching: parameter. In there you must provide a Query.

try collection.remove(matching: "first_name" == "Joannis") // Returns 1, only one user named "Joannis" exists

If you only want to remove one matching document:

try collection.remove(limitedTo: 1) // returns 1, only one Document may be removed. Any document will do because there is no matching filter

For more information about removing documents, click here

On this page