The API documentation is found here, however there are two entries:
and
both of which do not appear to use the form I am using as I am explicitly using the form below, while the docs use it as a place holder for such things as Character or product.
const Model = mongoose.model(name, schema);
Model.deleteOne()
My delete is working fine but I want to read the actual documentation for my function.
If I specify nothing then nothing happens. In fact not a lot useful happens ....UnhandledPromiseRejectionWarning: MongoServerError: BSON field 'delete.deletes.q' is missing but a required field.
So we must use the param filter and provide a doc to filter and delete:
(method) Collection<Document>.deleteOne(filter: Filter<Document>): Promise<DeleteResult> (+3 overloads)
Delete a document from a collection
@param filter — The filter used to select the document to remove
@param options — Optional settings for the command
@param callback — An optional callback, a Promise will be returned if none
So like so like the defintion says Collection<Document>.deleteOne({_id: 12345})
OR
delete = (x) => { if(x) db.collection.deleteOne({_id: x});
return 'you must provide a value to delete for field _id';
}
Are you sure your method deletes one or more docs without a filter?