code: def get_or_create(cls, spec, defaults=None):
          '''Find or create single document. Return (doc, created_now).'''
          docs = list(cls.find(spec).limit(2))
          assert len(docs) < 2, 'multiple docs returned'
          if docs:
              return docs[0], False
          else:
              kwargs = defaults or {}
              kwargs.update(spec)
              doc = cls(**kwargs)
              doc.save()
              return doc, Truf get_or_create(cls, spec, defaults=None):
          '''Find or create single document. Return (doc, created_now).'''
          docs = list(cls.find(spec).limit(2))
          assert len(docs) < 2, 'multiple docs returned'
          if docs:
              return docs[0], False
          else:
              kwargs = defaults or {}
              kwargs.update(spec)
              doc = cls(**kwargs)
              doc.save()
              return doc, True
docs: Find or create single document. Return (doc, created_now).