public static function prepareToStore($value)
    {
        // if array - try to prepare every value
        if (is_array($value)) {
            foreach ($value as $k => $v) {
                $value[$k] = self::prepareToStore($v);
            }

            return $value;
        }

        // if scalar - return it
        if (!is_object($value)) {
            return $value;
        }

        // if internal mongo types - pass it as is
        if (TypeChecker::isInternalType($value)) {
            return $value;
        }

        // do not convert geo-json to array
        if ($value instanceof Geometry) {
            return $value->jsonSerialize();
        }

        // structure
        if ($value instanceof Structure) {
            // validate structure
            if (!$value->isValid()) {
                $exception = new InvalidDocumentException('Embedded document not valid');
                $exception->setDocument($value);
                throw $exception;
            }

            // get array from structure
            return $value->toArray();
        }

        // other objects convert to array
        return (array) $value;
    }