Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-360

There is not a isValid(object_id) method

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 2.3
    • Affects Version/s: None
    • Component/s: 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@mongodb.com Ross Lawley
            Reporter:
            ipedrazas Ivan Pedrazas
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: