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

There is not a isValid(object_id) method

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial - P5
    • Resolution: Fixed
    • None
    • 2.3
    • None

    Description

      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)

      Attachments

        Activity

          People

            ross@mongodb.com Ross Lawley
            ipedrazas Ivan Pedrazas
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: