Inserts new data into collection.
@param array|object $data data to be inserted.
@param array $options list of options in format: optionName => optionValue.
@return \MongoDB\BSON\ObjectID new record ID instance.
@throws Exception on failure.
436319
public function insert($data, $options = [])
    {
        return $this->database->createCommand()->insert($this->name, $data, $options);
    }
1131829
public function add($data = [])
    {
        $insertId = $this->db->insert($data)->into($this->table)->execute(FALSE);

        return $insertId;
    }
311533
public function insert(array $data, array $options = []) {
		return $this->getAdapter()->insert(
			$this->getTableName(),
			$data,
			$options
		);
	}
347423
protected function prepareResult(&$data, array $options)
    {
        if (!empty($options['unserialize']) && !empty($data)) {
            foreach ((array) $options['unserialize'] as $field) {
                $data[$field] = empty($data[$field]) ? array() : unserialize($data[$field]);
            }
        }
    }
675919
public function update($id, $data, array $options = []) {
        return $this->query(Query::UPDATE)
            ->where($this->getPrimaryKey(), $id)
            ->save($data, $options);
    }
610981
public function initialize(array $data, array $options = []): NodeInterface
    {
        if (!isset($data['id']) || !is_string($data['id']) || $data['id'] === '') {
            throw ValidationException::create('Field "id" must be a non-empty string.');
        }

        if (!preg_match('/^[0-9a-z\_]+$/i', $data['id'])) {
            throw ValidationException::create(
                'Field "id" must have only characters 0-9, a-z, A-Z or "_". Received: '.$data['id']
            );
        }

        $this->setId($data['id']);

        $this->addSubscriber($this);

        if (isset($data['name'])) {
            if (!is_string($data['name']) || $data['name'] === '') {
                throw ValidationException::create('Field "name" must be a non-empty string.');
            }

            $this->setName($data['name']);
        }

        if (isset($data['type'])) {
            if (!is_string($data['type']) || $data['type'] === '') {
                throw ValidationException::create('Field "type" must be a non-empty string.');
            }

            if (!preg_match('/^[0-9a-z\_]+$/i', $data['type'])) {
                throw ValidationException::create(
                    'Field "type" must have only characters 0-9, a-z, A-Z or "_". Received: '.$data['type']
                );
            }

            $this->setType($data['type']);
        }


        if (isset($data['metadata'])) {
            if (!is_array($data['metadata'])) {
                throw ValidationException::create('Field "metadata" must be an array.');
            }

            $this->setMetadata($data['metadata']);
        }

        if (isset($data['parent'])) {
            if (!is_object($data['parent'])
                || !($data['parent'] instanceof NodeInterface)
            ) {
                throw ValidationException::create(
                    'Field "parent" must be an instance of NodeInterface.'
                );
            }

            $this->addParent($data['parent']);
        }

        if (isset($data['children'])) {
            if (!is_array($data['children'])) {
                throw ValidationException::create('Field "children" must be an array.');
            }

            foreach ($data['children'] as $node) {
                if (!is_object($node) || !($node instanceof NodeInterface)) {
                    throw ValidationException::create(
                        'Field "children" must be an array of NodeInterface instances.'
                    );
                }

                $node->addParent($this);

                $this->addChild($node);
            }
        }

        return $this;
    }
701135
public function command(array $data, $options = [], &$hash = null)
    {
        try {
            $cursor = new \MongoCommandCursor($this->connection, $this->name, $data);
            $cursor->setReadPreference($this->getReadPreference());

            return iterator_to_array($cursor)[0];
        } catch (\MongoDB\Driver\Exception\Exception $e) {
            return ExceptionConverter::toResultArray($e);
        }
    }
139942
public function embedData($data, $options=[]) {
		$image = \Swift_Image::newInstance($data);
		if(isset($options['filename']))
			$image->setFilename($options['filename']);
		if(isset($options['mime']))
			$image->setContentType($options['mime']);
		return $this->embed($image);
	}
302208
public static function insertOne(array $data)
    {
        $db = static::getDb();
    
        $db->insert(
            (new self())->getSource(),
            array_values($data),
            array_keys($data)
        );

        return $db->lastInsertId();
    }
130624
public function insert(array $data, $options = [])
    {
        $maxRetries = $this->maxRetries;
        $tries = 0;

        // Check whether we're dealing with a batch insert.
        if (isset($data[0]) && is_array($data[0])) {
            // Insert using batchInsert
            do {
                try {
                    $result = $this->collection->batchInsert($data, $options);
                    break;
                } catch (MongoCursorException $e) {
                    // Retry "save" in case of rediscovery latency issues
                    // in replica set failover. Error codes 10107, 13435, and 10058
                    // are MongoCursorException's "not master" errors.
                    if (in_array($e->getCode(), [10107, 13435, 10058])) {
                        if ($tries === $maxRetries) {
                            throw $e;
                        } else {
                            $tries++;
                            continue;
                        }
                    } else {
                        throw $e;
                    }
                }
            } while ($tries <= $maxRetries);

            if (! $result || ! ($result === true || (bool) $result['ok'])) {
                return false;
            }

            $result = [];

            foreach ($data as $r) {
                // Collect all the id's for the return value
                $result[] = $r['_id'];
            }

            // Return all inserted id's.
            return $result;
        }

        do {
            try {
                $result = $this->collection->insert($data, $options);
                break;
            } catch (MongoCursorException $e) {
                // Retry "save" in case of rediscovery latency issues
                // in replica set failover. Error codes 10107, 13435, and 10058
                // are MongoCursorException's "not master" errors.
                if (in_array($e->getCode(), [10107, 13435, 10058])) {
                    if ($tries === $maxRetries) {
                        throw $e;
                    } else {
                        $tries++;
                        continue;
                    }
                } else {
                    throw $e;
                }
            }
        } while ($tries <= $maxRetries);

        if ($result === true || (bool) $result['ok']) {
            return $data['_id'];
        }

        return false;
    }
439476
public function log($type, $data, $options = [])
    {
        if (!$this->config['debug']) {
            return;
        }

        if (is_array($data)) {
            array_walk_recursive($data, function (&$value) {
                if ($value instanceof ObjectID || $value instanceof \MongoDB\BSON\ObjectId) {
                    $value = $value->__toString();
                }
            });
        }

        switch (strtolower($type)) {
            case 'aggregate':
                $this->queryStr = 'runCommand(' . ($data ? json_encode($data) : '') . ');';
                break;
            case 'find':
                $this->queryStr = $type . '(' . ($data ? json_encode($data) : '') . ')';

                if (isset($options['sort'])) {
                    $this->queryStr .= '.sort(' . json_encode($options['sort']) . ')';
                }

                if (isset($options['limit'])) {
                    $this->queryStr .= '.limit(' . $options['limit'] . ')';
                }

                $this->queryStr .= ';';
                break;
            case 'insert':
            case 'remove':
                $this->queryStr = $type . '(' . ($data ? json_encode($data) : '') . ');';
                break;
            case 'update':
                $this->queryStr = $type . '(' . json_encode($options) . ',' . json_encode($data) . ');';
                break;
            case 'cmd':
                $this->queryStr = $data . '(' . json_encode($options) . ');';
                break;
        }

        $this->options = $options;
    }
88592
public function unpack(Data $data, array $options = null)
    {
        $defaults = ['dirty' => false];
        $options = $options ? array_merge($defaults, $options) : $defaults;

        $attributes = $this->getAttributes();

        $record = [];
        foreach ($data->pick(array_keys($attributes)) as $key => $value) {
            if ($options['dirty'] && !$data->isDirty($key)) {
                continue;
            }

            if ($value !== null) {
                $attribute = $attributes[$key];
                $value = Type::factory($attribute['type'])->store($value, $attribute);
            }

            $record[$key] = $value;
        }

        return $record;
    }
468615
protected function _entity(array $data = null, array $options = [])
    {
        if ($this->_entity && empty($data)) {
            return $this->_entity;
        }

        return $this->_table()->newEntity($data, $options);
    }
772173
public function createForm($data = null, array $options = [])
    {
        return $this->formFactory->create(NodeFormType::class, $data, $options);
    }
1341657
public function insert($data)
    {
        if(empty($data))
            throw new Exception("Can't insert an empty row");

        return $this->_connection->execute(sprintf(
            'INSERT INTO %s SET %s',
            $this->_name->quoted(),
            $this->_buildSet($data)
            ), array_values($data)
        );
    }
1346732
public static function insert($data)
    {
        $self  = self::getInstance();
        $table = $self->table_name;

        if (isset($data[0])) {
            $make      = $self->makeMultipleInsert($table, $data);
            $statement = $make[0];
            $value     = $make[1];
        } else {
            $newData    = $self->makeInsertParameter($data);
            $column     = implode(",", array_keys($data));
            $paramValue = implode(",", array_keys($newData));
            $statement  = "INSERT INTO {$table} ({$column}) VALUES({$paramValue});";
            $value      = $newData;
        }

        $execute   = $self->exec($statement, $value);

        return $execute;
    }
431891
public function saveCollection($data): Collection
    {
        $items = collect();

        foreach ($data as $optionData) {
            $item = $this->save($optionData, (int) ($optionData['id'] ?? 0));

            $items->push($item);
        }

        return $items;
    }