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

There is not a isValid(object_id) method

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial - P5
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3
    • Component/s: None
    • Labels:

      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

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: