Ejemplo n.º 1
0
 def __init__(self, filter, doc, upsert, collation, array_filters):
     if filter is not None:
         validate_is_mapping("filter", filter)
     if upsert is not None:
         validate_boolean("upsert", upsert)
     if array_filters is not None:
         validate_list("array_filters", array_filters)
     self._filter = filter
     self._doc = doc
     self._upsert = upsert
     self._collation = collation
     self._array_filters = array_filters
Ejemplo n.º 2
0
 def __init__(self, filter, doc, upsert, collation, array_filters):
     if filter is not None:
         validate_is_mapping("filter", filter)
     if upsert is not None:
         validate_boolean("upsert", upsert)
     if array_filters is not None:
         validate_list("array_filters", array_filters)
     self._filter = filter
     self._doc = doc
     self._upsert = upsert
     self._collation = collation
     self._array_filters = array_filters
Ejemplo n.º 3
0
    def __init__(self, filter, doc, upsert, collation, array_filters, hint):
        if filter is not None:
            validate_is_mapping("filter", filter)
        if upsert is not None:
            validate_boolean("upsert", upsert)
        if array_filters is not None:
            validate_list("array_filters", array_filters)
        if hint is not None:
            if not isinstance(hint, string_type):
                hint = helpers._index_document(hint)

        self._filter = filter
        self._doc = doc
        self._upsert = upsert
        self._collation = collation
        self._array_filters = array_filters
        self._hint = hint
Ejemplo n.º 4
0
    def __init__(self,
                 target,
                 cursor_class,
                 pipeline,
                 options,
                 explicit_session,
                 user_fields=None,
                 result_processor=None):
        if "explain" in options:
            raise ConfigurationError("The explain option is not supported. "
                                     "Use Database.command instead.")

        self._target = target

        common.validate_list('pipeline', pipeline)
        self._pipeline = pipeline
        self._performs_write = False
        if pipeline and ("$out" in pipeline[-1] or "$merge" in pipeline[-1]):
            self._performs_write = True

        common.validate_is_mapping('options', options)
        self._options = options

        # This is the batchSize that will be used for setting the initial
        # batchSize for the cursor, as well as the subsequent getMores.
        self._batch_size = common.validate_non_negative_integer_or_none(
            "batchSize", self._options.pop("batchSize", None))

        # If the cursor option is already specified, avoid overriding it.
        self._options.setdefault("cursor", {})
        # If the pipeline performs a write, we ignore the initial batchSize
        # since the server doesn't return results in this case.
        if self._batch_size is not None and not self._performs_write:
            self._options["cursor"]["batchSize"] = self._batch_size

        self._cursor_class = cursor_class
        self._explicit_session = explicit_session
        self._user_fields = user_fields
        self._result_processor = result_processor

        self._collation = validate_collation_or_none(
            options.pop('collation', None))

        self._max_await_time_ms = options.pop('maxAwaitTimeMS', None)
    def __init__(
        self,
        target: Union["MongoClient[_DocumentType]", "Database[_DocumentType]",
                      "Collection[_DocumentType]"],
        pipeline: Optional[_Pipeline],
        full_document: Optional[str],
        resume_after: Optional[Mapping[str, Any]],
        max_await_time_ms: Optional[int],
        batch_size: Optional[int],
        collation: Optional[_CollationIn],
        start_at_operation_time: Optional[Timestamp],
        session: Optional["ClientSession"],
        start_after: Optional[Mapping[str, Any]],
        comment: Optional[Any] = None,
    ) -> None:
        if pipeline is None:
            pipeline = []
        pipeline = common.validate_list("pipeline", pipeline)
        common.validate_string_or_none("full_document", full_document)
        validate_collation_or_none(collation)
        common.validate_non_negative_integer_or_none("batchSize", batch_size)

        self._decode_custom = False
        self._orig_codec_options = target.codec_options
        if target.codec_options.type_registry._decoder_map:
            self._decode_custom = True
            # Keep the type registry so that we support encoding custom types
            # in the pipeline.
            self._target = target.with_options(  # type: ignore
                codec_options=target.codec_options.with_options(
                    document_class=RawBSONDocument))
        else:
            self._target = target

        self._pipeline = copy.deepcopy(pipeline)
        self._full_document = full_document
        self._uses_start_after = start_after is not None
        self._uses_resume_after = resume_after is not None
        self._resume_token = copy.deepcopy(start_after or resume_after)
        self._max_await_time_ms = max_await_time_ms
        self._batch_size = batch_size
        self._collation = collation
        self._start_at_operation_time = start_at_operation_time
        self._session = session
        self._comment = comment
        # Initialize cursor.
        self._cursor = self._create_cursor()