首页 > 解决方案 > 没有从查询执行中得到准确的结果

问题描述

我正在使用CodeIgniterwithMongoDB并希望使用保存在 MongoDB 中的 id 获取数据我执行一个打印数据的查询,但我不明白要打印什么数据

我执行这个查询

$query=$this->mongo_db->where('posts', array('_id' => new \MongoDB\BSON\ObjectID($id)));

并获取此结果而不是任何数据

Mongo_db Object
(
  [CodeIgniter:Mongo_db:private] => User Object
    (
        [benchmark] => CI_Benchmark Object
            (
                [marker] => Array
                    (
                        [total_execution_time_start] => 1559113613.9923
                        [loading_time:_base_classes_start] => 1559113613.9923
                        [loading_time:_base_classes_end] => 1559113614.0023
                        [controller_execution_time_( User / single )_start] => 1559113614.0023
                    )

            )

        [hooks] => CI_Hooks Object
            (
                [enabled] => 
                [hooks] => Array
                    (
                    )

                [_objects:protected] => Array
                    (
                    )

                [_in_progress:protected] => 
            )

        [config] => CI_Config Object
            (
                [config] => Array
                    (
                        [base_url] => http://localhost/chronicle/
                        [index_page] => index.php
                        [uri_protocol] => REQUEST_URI
                        [url_suffix] => 
                        [language] => english
                        [charset] => UTF-8
                        [enable_hooks] => 
                        [subclass_prefix] => MY_
                        [composer_autoload] => 
                        [permitted_uri_chars] => a-z 0-9~%.:_\-
                        [enable_query_strings] => 
                        [controller_trigger] => c
                        [function_trigger] => m
                        [directory_trigger] => d
                        [allow_get_array] => 1
                        [log_threshold] => 0
                        [log_path] => 
                        [log_file_extension] => 
                        [log_file_permissions] => 420
                        [log_date_format] => Y-m-d H:i:s
                        [error_views_path] => 
                        [cache_path] => 
                        [cache_query_string] => 
                        [encryption_key] => 
                        [sess_driver] => files
                        [sess_cookie_name] => ci_session
                        [sess_expiration] => 7200
                        [sess_save_path] => 
                        [sess_match_ip] => 
                        [sess_time_to_update] => 300
                        [sess_regenerate_destroy] => 
                        [cookie_prefix] => 
                        [cookie_domain] => 
                        [cookie_path] => /
                        [cookie_secure] => 
                        [cookie_httponly] => 
                        [standardize_newlines] => 
                        [global_xss_filtering] => 
                        [csrf_protection] => 
                        [csrf_token_name] => csrf_test_name
                        [csrf_cookie_name] => csrf_cookie_name
                        [csrf_expire] => 7200
                        [csrf_regenerate] => 1
                        [csrf_exclude_uris] => Array
                            (
                            )

                        [compress_output] => 
                        [time_reference] => local
                        [rewrite_short_tags] => 
                        [proxy_ips] => 
                        [mongo_db] => Array
                            (
                                [active_config_group] => default
                                [default] => Array
                                    (
                                        [settings] => Array
                                            (
                                                [auth] => 1
                                                [debug] => 1
                                                [return_as] => array
                                                [auto_reset_query] => 1
                                            )

                                        [connection_string] => 
                                        [connection] => Array
                                            (
                                                [host] => 127.0.0.1
                                                [port] => 27017
                                                [user_name] => admin
                                                [user_password] => admin
                                                [db_name] => centralchronicle
                                                [db_options] => Array
                                                    (
                                                    )

                                            )

                                        [driver] => Array
                                            (
                                            )

                                    )

                            )

                    )

                [is_loaded] => Array
                    (
                        [0] => D:\xampp\htdocs\chronicle\application\config/mongo_db.php
                    )

                [_config_paths] => Array
                    (
                        [0] => D:\xampp\htdocs\chronicle\application\
                    )

            )

        [log] => CI_Log Object
            (
                [_log_path:protected] => D:\xampp\htdocs\chronicle\application\logs/
                [_file_permissions:protected] => 420
                [_threshold:protected] => 0
                [_threshold_array:protected] => Array
                    (
                    )

                [_date_fmt:protected] => Y-m-d H:i:s
                [_file_ext:protected] => php
                [_enabled:protected] => 1
                [_levels:protected] => Array
                    (
                        [ERROR] => 1
                        [DEBUG] => 2
                        [INFO] => 3
                        [ALL] => 4
                    )

            )

        [utf8] => CI_Utf8 Object
            (
            )

        [uri] => CI_URI Object
            (
                [keyval] => Array
                    (
                    )

                [uri_string] => User/single/5ced0e57ed4e3e0fbc017e19
                [segments] => Array
                    (
                        [1] => User
                        [2] => single
                        [3] => 5ced0e57ed4e3e0fbc017e19
                    )

                [rsegments] => Array
                    (
                        [1] => User
                        [2] => single
                        [3] => 5ced0e57ed4e3e0fbc017e19
                    )

                [_permitted_uri_chars:protected] => a-z 0-9~%.:_\-
                [config] => CI_Config Object
                    (
                        [config] => Array
                            (
                                [base_url] => http://localhost/chronicle/
                                [index_page] => index.php
                                [uri_protocol] => REQUEST_URI
                                [url_suffix] => 
                                [language] => english
                                [charset] => UTF-8
                                [enable_hooks] => 
                                [subclass_prefix] => MY_
                                [composer_autoload] => 
                                [permitted_uri_chars] => a-z 0-9~%.:_\-
                                [enable_query_strings] => 
                                [controller_trigger] => c
                                [function_trigger] => m
                                [directory_trigger] => d
                                [allow_get_array] => 1
                                [log_threshold] => 0
                                [log_path] => 
                                [log_file_extension] => 
                                [log_file_permissions] => 420
                                [log_date_format] => Y-m-d H:i:s
                                [error_views_path] => 
                                [cache_path] => 
                                [cache_query_string] => 
                                [encryption_key] => 
                                [sess_driver] => files
                                [sess_cookie_name] => ci_session
                                [sess_expiration] => 7200
                                [sess_save_path] => 
                                [sess_match_ip] => 
                                [sess_time_to_update] => 300
                                [sess_regenerate_destroy] => 
                                [cookie_prefix] => 
                                [cookie_domain] => 
                                [cookie_path] => /
                                [cookie_secure] => 
                                [cookie_httponly] => 
                                [standardize_newlines] => 
                                [global_xss_filtering] => 
                                [csrf_protection] => 
                                [csrf_token_name] => csrf_test_name
                                [csrf_cookie_name] => csrf_cookie_name
                                [csrf_expire] => 7200
                                [csrf_regenerate] => 1
                                [csrf_exclude_uris] => Array
                                    (
                                    )

                                [compress_output] => 
                                [time_reference] => local
                                [rewrite_short_tags] => 
                                [proxy_ips] => 
                                [mongo_db] => Array
                                    (
                                        [active_config_group] => default
                                        [default] => Array
                                            (
                                                [settings] => Array
                                                    (
                                                        [auth] => 1
                                                        [debug] => 1
                                                        [return_as] => array
                                                        [auto_reset_query] => 1
                                                    )

                                                [connection_string] => 
                                                [connection] => Array
                                                    (
                                                        [host] => 127.0.0.1
                                                        [port] => 27017
                                                        [user_name] => admin
                                                        [user_password] => admin
                                                        [db_name] => centralchronicle
                                                        [db_options] => Array
                                                            (
                                                            )

                                                    )

                                                [driver] => Array
                                                    (
                                                    )

                                            )

                                    )

                            )

                        [is_loaded] => Array
                            (
                                [0] => D:\xampp\htdocs\chronicle\application\config/mongo_db.php
                            )

                        [_config_paths] => Array
                            (
                                [0] => D:\xampp\htdocs\chronicle\application\
                            )

                    )

            )

        [router] => CI_Router Object
            (
                [config] => CI_Config Object
                    (
                        [config] => Array
                            (
                                [base_url] => http://localhost/chronicle/
                                [index_page] => index.php
                                [uri_protocol] => REQUEST_URI
                                [url_suffix] => 
                                [language] => english
                                [charset] => UTF-8
                                [enable_hooks] => 
                                [subclass_prefix] => MY_
                                [composer_autoload] => 
                                [permitted_uri_chars] => a-z 0-9~%.:_\-
                                [enable_query_strings] => 
                                [controller_trigger] => c
                                [function_trigger] => m
                                [directory_trigger] => d
                                [allow_get_array] => 1
                                [log_threshold] => 0
                                [log_path] => 
                                [log_file_extension] => 
                                [log_file_permissions] => 420
                                [log_date_format] => Y-m-d H:i:s
                                [error_views_path] => 
                                [cache_path] => 
                                [cache_query_string] => 
                                [encryption_key] => 
                                [sess_driver] => files
                                [sess_cookie_name] => ci_session
                                [sess_expiration] => 7200
                                [sess_save_path] => 
                                [sess_match_ip] => 
                                [sess_time_to_update] => 300
                                [sess_regenerate_destroy] => 
                                [cookie_prefix] => 
                                [cookie_domain] => 
                                [cookie_path] => /
                                [cookie_secure] => 
                                [cookie_httponly] => 
                                [standardize_newlines] => 
                                [global_xss_filtering] => 
                                [csrf_protection] => 
                                [csrf_token_name] => csrf_test_name
                                [csrf_cookie_name] => csrf_cookie_name
                                [csrf_expire] => 7200
                                [csrf_regenerate] => 1
                                [csrf_exclude_uris] => Array
                                    (
                                    )

                                [compress_output] => 
                                [time_reference] => local
                                [rewrite_short_tags] => 
                                [proxy_ips] => 
                                [mongo_db] => Array
                                    (
                                        [active_config_group] => default
                                        [default] => Array
                                            (
                                                [settings] => Array
                                                    (
                                                        [auth] => 1
                                                        [debug] => 1
                                                        [return_as] => array
                                                        [auto_reset_query] => 1
                                                    )

                                                [connection_string] => 
                                                [connection] => Array
                                                    (
                                                        [host] => 127.0.0.1
                                                        [port] => 27017
                                                        [user_name] => admin
                                                        [user_password] => admin
                                                        [db_name] => centralchronicle
                                                        [db_options] => Array
                                                            (
                                                            )

                                                    )

                                                [driver] => Array
                                                    (
                                                    )

                                            )

                                    )

                            )

                        [is_loaded] => Array
                            (
                                [0] => D:\xampp\htdocs\chronicle\application\config/mongo_db.php
                            )

                        [_config_paths] => Array
                            (
                                [0] => D:\xampp\htdocs\chronicle\application\
                            )

标签: mongodbcodeigniter

解决方案


推荐阅读