collection.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:mongodb-monitoring 作者: jruaux 项目源码 文件源码
def _insert_one(
            self, sock_info, doc, ordered,
            check_keys, manipulate, write_concern, op_id, bypass_doc_val):
        """Internal helper for inserting a single document."""
        if manipulate:
            doc = self.__database._apply_incoming_manipulators(doc, self)
            if not isinstance(doc, RawBSONDocument) and '_id' not in doc:
                doc['_id'] = ObjectId()
            doc = self.__database._apply_incoming_copying_manipulators(doc,
                                                                       self)
        concern = (write_concern or self.write_concern).document
        acknowledged = concern.get("w") != 0
        command = SON([('insert', self.name),
                       ('ordered', ordered),
                       ('documents', [doc])])
        if concern:
            command['writeConcern'] = concern

        if sock_info.max_wire_version > 1 and acknowledged:
            if bypass_doc_val and sock_info.max_wire_version >= 4:
                command['bypassDocumentValidation'] = True
            # Insert command.
            result = sock_info.command(self.__database.name,
                                       command,
                                       codec_options=self.codec_options,
                                       check_keys=check_keys)
            _check_write_command_response([(0, result)])
        else:
            # Legacy OP_INSERT.
            self._legacy_write(
                sock_info, 'insert', command, acknowledged, op_id,
                bypass_doc_val, message.insert, self.__full_name, [doc],
                check_keys, acknowledged, concern, False, self.codec_options)
        if not isinstance(doc, RawBSONDocument):
            return doc.get('_id')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号