0

Suppose there is a web application that shows some videos. I think it is common case when design its url (not API).

http://myservice.com/videos/{video-id}

The strategy is fine when use RDBMS implementations because ids are generally very short but, I've struggled against the problem from using MongoDB.

MySQL case: http://myservice.com/videos/1

Mongo case: http://myservice.com/videos/57932d53a1b33ab926ab54b3

IMHO, it is too long to represent url. I don't want to see like below

http://myservice.com/videos/57932d53a1b33ab926ab54b3/comments/57932d53a1b33ab926ab54c2

Do I have to change a way as like representing video's name or number of sort order? Is there a better idea to represent identifier?

Jinyoung Kim
  • 1,885
  • 3
  • 14
  • 23

1 Answers1

0

The ids you gave as example look like autogenerated ObjectId values. You can use any values to represent the _id field as long as they are unique within a single collection.

The field name _id is reserved for use as a primary key; its value must be unique in the collection, is immutable, and may be of any type other than an array. (See the documentation)

Another approach is to add a field in readable format to your document for the url forming purpose (and create a unique index for it if needed).

Andriy Simonov
  • 1,276
  • 1
  • 11
  • 19