[GODRIVER-838] DeleteMany not working as expected Created: 19/Feb/19  Updated: 27/Oct/23  Resolved: 14/Mar/19

Status: Closed
Project: Go Driver
Component/s: API, BSON, Documentation
Affects Version/s: 0.3.0
Fix Version/s: None

Type: Task Priority: Minor - P4
Reporter: Andrea Medda Assignee: Jeffrey Yemin
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS



 Description   

Using DeleteMany with more than one bson.D always generates an error.

In the examples, it's possible to find a DeleteMany example but it actually deletes only one bson.D:

 

result, err := coll.DeleteMany(context.Background(),			       bson.D{{"status", "A"},},)

 But what if I want to delete more documents?

I tried with:

[]interface{}{ bson.D{"_id" : "someId"}, bson.D{"_id" : "someOtherId"} }

But I got: cannot transform type []interface{} to a *bsonx.Document

And even with:

[]bson.D{ bson.D{"_id" : "someId"}, bson.D{"_id" : "someOtherId"} }

 

But I got*: cannot transform type []primitive.D to a bsonx.Document

 
I feel like it's also needed a proper example & the API of this method should be similar to InsertMany.

 



 Comments   
Comment by Ian Whalen (Inactive) [ 25/Feb/19 ]

Hi andream16, sorry to hear you're having trouble. DeleteMany is working as specified; in this case the "many" refers to the number of documents to delete which match the provided query filter. It's distinguished from DeleteOne in that DeleteOne will delete only one matching document. if you're looking to delete documents that match more than one query filter, you should use either:

  • a single DeleteMany with a filter combining multiple conditions with $or
  • the BulkWrite method
Generated at Thu Feb 08 08:35:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.