Delete Multiple Documents![](/docs/drivers/go/v1.8/assets/link.svg)
This version of the documentation is archived and no longer supported. View the current documentation to learn how to upgrade your version of the MongoDB Go Driver.
You can delete multiple documents in a collection by using the
DeleteMany()
method.
Example![](/docs/drivers/go/v1.8/assets/link.svg)
Tip
Read the Usage Examples to learn how to run this example.
The following example matches documents in the movies
collection
in which the runtime
is greater than 800 minutes, deleting all
documents matched:
coll := client.Database("sample_mflix").Collection("movies") filter := bson.D{{"runtime", bson.D{{"$gt", 800}}}} results, err := coll.DeleteMany(context.TODO(), filter) if err != nil { panic(err) }
View a fully runnable example.
Expected Result![](/docs/drivers/go/v1.8/assets/link.svg)
After you run the full example, it removes the following documents
in the movies
collection:
// results truncated { "_id": ObjectId("573a1397f29313caabce69db"), ... , "runtime": 1256, ... }, { "_id": ObjectId("573a1397f29313caabce75fe"), ... , "runtime": 910, ... }, { "_id": ObjectId("573a1399f29313caabcee1aa"), ... , "runtime": 1140, ... }, { "_id": ObjectId("573a13a6f29313caabd18ae0"), ... , "runtime": 877, ... }
For an example on how to find multiple documents, see Find Multiple Documents.
Additional Information![](/docs/drivers/go/v1.8/assets/link.svg)
To learn more about deleting documents, see Delete Documents.