Open hjr265 opened 5 years ago
I can send a pull request for this if you want.
No, when you create file via GridFS(..).Create(....), id will be created. return file, error. you can get id from func (*GridFile) Id
refer to code line 174, below
func (gfs *GridFS) Create(name string) (file *GridFile, err error) {
file = gfs.newFile()
file.mode = gfsWriting
file.wsum = md5.New()
file.doc = gfsFile{Id: bson.NewObjectId(), ChunkSize: 255 * 1024, Filename: name}
return
}
@lujiacn Thanks, but I was referring to the creation of database indices, not IDs.
According to the GridFS specification, there should exist an index on the files collection (ref):
I did a quick scan of the gridfs.go file and it seems the only index that is created in that file is the second one: https://github.com/globalsign/mgo/blob/eeefdecb41b842af6dc652aaea4026e8403e62df/gridfs.go#L561
I can confirm that this behavior of having only the second index created is consistent in one of my production setup (which is how I discovered this potential issue). Unless I am missing something obvious (I am sorry if I am), I think this is a deviation from the specification and should be worth correcting.
What version of MongoDB are you using (
mongod --version
)?What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
N/A
Can you reproduce the issue on the latest
development
branch?The gridfs.go file in the latest development branch also has one call to EnsureIndex and that is on the chunks collection: https://github.com/globalsign/mgo/blob/909ae7ce1a7b88428b6e2aa3f1c67444b193b382/gridfs.go#L561