[GODRIVER-1623] DeleteOptions Hint is not working on DeleteMany Created: 25/May/20  Updated: 27/Oct/23  Resolved: 28/May/20

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Aravind Kumar Assignee: Divjot Arora (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

DeleteOptions Hint in deleteMany is not working.

Error: (Location40415) BSON field 'delete.deletes.hint' is an unknown field.

Code:
deleteOptions := &options.DeleteOptions{
Hint: bson.M

{"example": 1}

,
}
_, err = coll.DeleteMany(ctx, filter, deleteOptions)
 



 Comments   
Comment by Aravind Kumar [ 28/May/20 ]

we can close this

Comment by Divjot Arora (Inactive) [ 27/May/20 ]

Seems like the shell accepts any options and silently ignores them if they're not correct. The only documented options listed on https://docs.mongodb.com/manual/reference/method/db.collection.deleteMany/ are collation and writeConcern. I tried running

db.collectionName.deleteMany({}, {foo: {key: 1}})

and it succeeded as well. The ability to pass a hint to the delete command was added in SERVER-44367, which has a fix version of 4.3.4, so this functionality will be available in the 4.4 server release.

Can we close out this issue as "works as designed"?

Comment by Aravind Kumar [ 27/May/20 ]

in server version 4.0.7, db.collectionName.deleteMany({}, {hint: {key: 1}}) is working fine, but dont see any documentation officially.

Comment by Divjot Arora (Inactive) [ 26/May/20 ]

I can't repro the installation weirdness. Using Go1.14 on Ubuntu 16.04, running go get go.mongodb.org/mongo-driver/mongo fetches v1.3.3 of the driver, not v1.4.0-beta1. This is the expected behavior as v1.4.0-beta1 is a pre-release. It's weird to me that running the command gets a different version of the package for you.

Regardless, per our documentation at https://godoc.org/go.mongodb.org/mongo-driver/mongo/options#DeleteOptions, the hint option is only available for DeleteOne/DeleteMany on server versions 4.4 and above. Server versions between 3.4 and 4.2, inclusive, will return an error if the option is used, which is what you're seeing.

Comment by Aravind Kumar [ 26/May/20 ]

server version: 4.0.7

I'm directly installing the package using
go get go.mongodb.org/mongo-driver/mongo

Comment by Divjot Arora (Inactive) [ 26/May/20 ]

Hi aravind.4svg@gmail.com,

Can you let us know which server version you're using? I assume you're using driver version v1.4.0-beta1 as DeleteOptions.Hint was not available in the 1.3.x releases.

– Divjot

Generated at Thu Feb 08 08:36:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.