You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to retrieve the ObjectId (or even filename) from the callback, and this even if there was an error. At least, I have not figured out how to do so. To illustrate, this is what I am trying to achieve.
I would like to have efficient, implicit deduplication when a document is inserted in GridFS. My root name is "attachments", for this example. To do so, I have created a unique index on the "md5" field in the attachment.files collection. This means that there should be an error if a filename with the same md5 hash is inserted. And I can then handle it, although I don't know how to retrieve the ObjectID or md5 hash from this transaction.
There is a problem with this: when the document is inserted, It is first created in attachments.chunks, and then hashed, and only then the attachment.files entry is attempted to be created, and raises the error if there's a duplicate. Which means there are dangling chunks with no corresponding files entry. Again, if I could know what the ObjectId was at the moment the attempt was made, I could handle it and simply remove the duplicate chunks. How do I do this?
My workaround is a naive approach where I manually md5 hash the file before and checking if it exists before attempting to insert, but that seems to me inefficient, since it will be hashed a second time.
The text was updated successfully, but these errors were encountered:
@Andargor so you want a callback to be exposed for the handleFile and removeFile functions giving you the ObjectId of the file been inserted/removed?
If this is true, I will work on adding support for it!
@JonatanSalas Yes, getting the ObjectId whether the insert succeeds or fails would satisfy the request so there can be cleaning up on an error. Or setting it in advance so it can be used to handle the error.
In the meantime I've implemented my "naive" approach, so this is not an emergency. :)
I would like to retrieve the ObjectId (or even filename) from the callback, and this even if there was an error. At least, I have not figured out how to do so. To illustrate, this is what I am trying to achieve.
I would like to have efficient, implicit deduplication when a document is inserted in GridFS. My root name is "attachments", for this example. To do so, I have created a unique index on the "md5" field in the attachment.files collection. This means that there should be an error if a filename with the same md5 hash is inserted. And I can then handle it, although I don't know how to retrieve the ObjectID or md5 hash from this transaction.
There is a problem with this: when the document is inserted, It is first created in attachments.chunks, and then hashed, and only then the attachment.files entry is attempted to be created, and raises the error if there's a duplicate. Which means there are dangling chunks with no corresponding files entry. Again, if I could know what the ObjectId was at the moment the attempt was made, I could handle it and simply remove the duplicate chunks. How do I do this?
My workaround is a naive approach where I manually md5 hash the file before and checking if it exists before attempting to insert, but that seems to me inefficient, since it will be hashed a second time.
The text was updated successfully, but these errors were encountered: