0

We are developing photo gallery which is storing huge amount of photos. We have choosed MongoDB's GridFS for image storage. Every thing looks fine.

But every time when user has to delete the photo we thought of deleting particular photo based on its "ObjectId", but Sending ObjectId to client side looks ugly because of its length. Deleting based on photo name is not possible because its not unique.

So how do we prettify the ObjectId to send it to client side?

sravis
  • 3,562
  • 6
  • 36
  • 73
  • 2
    "looks ugly" to whom? – chrisbajorin Mar 13 '15 at 15:07
  • 2
    you could, for instance, devise an algorithm that has similar low collision probability while at the same time guaranteeing prettyness. Your gravatar icon is a pretty version of the hash of your email. You could turn that around and upload a picture every time instead of using an id... No, to be honest: why would the user even *see* the id? Shouldn't that be an ajax request? – mnemosyn Mar 13 '15 at 15:18

1 Answers1

0

Not sure if this belongs as an answer since it's subjective, but then again, so is the question:

If you want to not involve another field, you can change the encoding of the id. I think base64 looks just fine:

55036ee50202b73c1a021897 -> NTUwMzZlZTUwMjAyYjczYzFhMDIxODk3

Another option is to generate a random string and store it on the document, which gives you a lot of customizability in the appearance. For example, you could do 4 digit codes with only upper-case characters like BUZQ. However, be sure to create a unique index so you don't accidentally create duplicate identifiers.

jtmarmon
  • 5,727
  • 7
  • 28
  • 45