There is not a isValid(object_id) method

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Done
    • Priority: Trivial - P5
    • 2.3
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      There is not an easy/clean way to check if a string is a valid ObjectId.

      I have implemented the method myself but it would be nice to have it (even if it's the way the Java driver does).

      I have an API that receives ids that I have to use to find objects. Right now, I do MongoUtils.isValidId(object_id) but it would be good if I could do something like

      if ObjectId.isValid(object_id):
      doc =

      {'_id' : ObjectId(object_id)}

      result = db.col.find(doc)

            Assignee:
            Ross Lawley
            Reporter:
            Ivan Pedrazas
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: