mongoadmin icon indicating copy to clipboard operation
mongoadmin copied to clipboard

What to do when _id is not an ObjectID

Open JeffAMcGee opened this issue 13 years ago • 0 comments

Mongoadmin crashes or throws a 404 when you attempt to change a document with an _id that is not an ObjectId. @lbjay tried to fix this problem in the adsabs/mongoadmin repo with code similar to pull request #5. Both branches appear to work when the _id is a string, but they don't work when _id is an integer. I have a database where the _ids are all integers. Mongo supports a wide range of types for _id including floats, ints, strs, bools, ObjectIds, datetimes, and dicts.

I see two ways to fix this:

  1. Make mongoadmin work when _id is a string, int, or ObjectId, and use some heuristics to distinguish between the cases. The advantage of this is that the urls can stay the same; however, if a database contains both {_id:10} and {_id:"10"} there will never be a way to distinguish them.
  2. Change the urls to include the json-encoded _id field. This will preserve type information, but make the urls uglier. This will work with almost any valid _id using mongo's extended json.

I'd like to fix it, but I want to figure out the best solution first.

JeffAMcGee avatar Jan 25 '13 20:01 JeffAMcGee