__init__.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # Copyright 2009-present MongoDB, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """Python driver for MongoDB."""
  15. ASCENDING = 1
  16. """Ascending sort order."""
  17. DESCENDING = -1
  18. """Descending sort order."""
  19. GEO2D = "2d"
  20. """Index specifier for a 2-dimensional `geospatial index`_.
  21. .. _geospatial index: http://docs.mongodb.org/manual/core/2d/
  22. """
  23. GEOHAYSTACK = "geoHaystack"
  24. """**DEPRECATED** - Index specifier for a 2-dimensional `haystack index`_.
  25. **DEPRECATED** - :attr:`GEOHAYSTACK` is deprecated and will be removed in
  26. PyMongo 4.0. geoHaystack indexes (and the geoSearch command) were deprecated
  27. in MongoDB 4.4. Instead, create a 2d index and use $geoNear or $geoWithin.
  28. See https://dochub.mongodb.org/core/4.4-deprecate-geoHaystack.
  29. .. versionchanged:: 3.11
  30. Deprecated.
  31. .. _haystack index: http://docs.mongodb.org/manual/core/geohaystack/
  32. """
  33. GEOSPHERE = "2dsphere"
  34. """Index specifier for a `spherical geospatial index`_.
  35. .. versionadded:: 2.5
  36. .. _spherical geospatial index: http://docs.mongodb.org/manual/core/2dsphere/
  37. """
  38. HASHED = "hashed"
  39. """Index specifier for a `hashed index`_.
  40. .. versionadded:: 2.5
  41. .. _hashed index: http://docs.mongodb.org/manual/core/index-hashed/
  42. """
  43. TEXT = "text"
  44. """Index specifier for a `text index`_.
  45. .. seealso:: MongoDB's `Atlas Search
  46. <https://docs.atlas.mongodb.com/atlas-search/>`_ which offers more advanced
  47. text search functionality.
  48. .. versionadded:: 2.7.1
  49. .. _text index: http://docs.mongodb.org/manual/core/index-text/
  50. """
  51. OFF = 0
  52. """**DEPRECATED** - No database profiling.
  53. **DEPRECATED** - :attr:`OFF` is deprecated and will be removed in PyMongo 4.0.
  54. Instead, specify this profiling level using the numeric value ``0``.
  55. See https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler
  56. .. versionchanged:: 3.12
  57. Deprecated
  58. """
  59. SLOW_ONLY = 1
  60. """**DEPRECATED** - Only profile slow operations.
  61. **DEPRECATED** - :attr:`SLOW_ONLY` is deprecated and will be removed in
  62. PyMongo 4.0. Instead, specify this profiling level using the numeric
  63. value ``1``.
  64. See https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler
  65. .. versionchanged:: 3.12
  66. Deprecated
  67. """
  68. ALL = 2
  69. """**DEPRECATED** - Profile all operations.
  70. **DEPRECATED** - :attr:`ALL` is deprecated and will be removed in PyMongo 4.0.
  71. Instead, specify this profiling level using the numeric value ``2``.
  72. See https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler
  73. .. versionchanged:: 3.12
  74. Deprecated
  75. """
  76. version_tuple = (3, 12, 0)
  77. def get_version_string():
  78. if isinstance(version_tuple[-1], str):
  79. return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
  80. return '.'.join(map(str, version_tuple))
  81. __version__ = version = get_version_string()
  82. """Current version of PyMongo."""
  83. from pymongo.collection import ReturnDocument
  84. from pymongo.common import (MIN_SUPPORTED_WIRE_VERSION,
  85. MAX_SUPPORTED_WIRE_VERSION)
  86. from pymongo.cursor import CursorType
  87. from pymongo.mongo_client import MongoClient
  88. from pymongo.mongo_replica_set_client import MongoReplicaSetClient
  89. from pymongo.operations import (IndexModel,
  90. InsertOne,
  91. DeleteOne,
  92. DeleteMany,
  93. UpdateOne,
  94. UpdateMany,
  95. ReplaceOne)
  96. from pymongo.read_preferences import ReadPreference
  97. from pymongo.write_concern import WriteConcern
  98. def has_c():
  99. """Is the C extension installed?"""
  100. try:
  101. from pymongo import _cmessage
  102. return True
  103. except ImportError:
  104. return False