MongoDB - 从对象内的数组中查找数据(MongoDB - Find Data from a array inside a object)
我有以下形式的数据库
{ "_id" : ObjectId("56fc92adcf908c9f296e5885"), "_class" : "com.abc.ppm.dto.AccessAttemptDTO", "url" : "/myProject/edit", "ipAddress" : "127.0.0.1", "param" : { "iecode" : [ "P1234" ], "id" : [ "5696578c6d34f835dc632fdd " ] }, "accessTime" : "30-3-2016 10:59:57", "email" : "abc@gmail.com", "entity" : "admin", "entityCode" : "" }, { "_id" : ObjectId("56fc92adcf908c9f296e5887"), "_class" : "com.abc.ppm.dto.AccessAttemptDTO", "url" : "/myProject/edit", "ipAddress" : "127.0.0.1", "param" : { "iecode" : [ "P1122" ], "id" : [ "5696578c6d34f835dc632fdd " ] }, "accessTime" : "30-3-2016 10:59:57", "email" : "abc@gmail.com", "entity" : "admin", "entityCode" : ""
}
现在我想找到iecode为'P1234'的所有enries。 我怎么做? (注意:iecodes值以字符串数组格式存储。)
I have my db in following form
{ "_id" : ObjectId("56fc92adcf908c9f296e5885"), "_class" : "com.abc.ppm.dto.AccessAttemptDTO", "url" : "/myProject/edit", "ipAddress" : "127.0.0.1", "param" : { "iecode" : [ "P1234" ], "id" : [ "5696578c6d34f835dc632fdd " ] }, "accessTime" : "30-3-2016 10:59:57", "email" : "abc@gmail.com", "entity" : "admin", "entityCode" : "" }, { "_id" : ObjectId("56fc92adcf908c9f296e5887"), "_class" : "com.abc.ppm.dto.AccessAttemptDTO", "url" : "/myProject/edit", "ipAddress" : "127.0.0.1", "param" : { "iecode" : [ "P1122" ], "id" : [ "5696578c6d34f835dc632fdd " ] }, "accessTime" : "30-3-2016 10:59:57", "email" : "abc@gmail.com", "entity" : "admin", "entityCode" : ""
}
Now I want to find all the enries where iecode is 'P1234'. How do I do that? (Note: iecodes value is stored in string array format.)
原文:https://stackoverflow.com/questions/37087048
最满意答案
解决方案很简单,但IDE和调试器都没有说明它。 它只返回
null
。 当您使用php artisan config:cache
,根据文档:如果您在部署过程中执行
php artisan config:cache
命令,则应确保只从配置文件中调用env()
函数。显然我在配置文件之外有
env
变量,所以在缓存之后我再也无法在外面使用它了。php artisan config:clear
让它重新投入使用。我发现更多关于
env
的用法,它只能在配置文件中使用。 您可以使用其他帮助程序方法config()
从项目的其余部分访问env
变量。 确保将其分配给配置文件中的另一个键,例如'key' => env('CACHE_DRIVER')
更重要的是,你必须记住每次你改变
.env
文件时运行php artisan config:cache
。 Laravel不会加载新值,直到它被缓存。 如果它没有被缓存,则不需要这样做。The solution is simple, but not IDE nor debugger tells anything about it. It just returns
null
. When you usephp artisan config:cache
, according to documentation:If you execute
php artisan config:cache
command during your deployment process, you should be sure that you are only calling theenv()
function from within your configuration files.Obviously I have
env
variables outside the config files, so after caching I was not able to use it outside anymore. Thephp artisan config:clear
puts it back to work.What I've found more about the usage of
env
, that it should be used only within config files. You can accessenv
variables from the rest of the project using other helper methodconfig()
. Be sure to assign it to another key in config file, e.g.'key' => env('CACHE_DRIVER')
What is more, you have to remember to run
php artisan config:cache
each time you will change.env
file. Laravel will not load the new values, until it's cached. If it's not cached, no need to do it.
相关问答
更多-
从官方Laravel 5.2升级说明: 如果您在部署期间使用config:cache命令,则必须确保您只在配置文件中调用env函数,而不是在应用程序中的任何其他位置调用该函数。 如果您在应用程序中调用env ,强烈建议您将适当的配置值添加到配置文件中,然后从该位置调用env ,以允许将env调用转换为config调用。 参考: https : //laravel.com/docs/5.2/upgrade#upgrade-5.2.0 Wow. Good grief. It's because I had an ...
-
解决方案很简单,但IDE和调试器都没有说明它。 它只返回null 。 当您使用php artisan config:cache ,根据文档: 如果您在部署过程中执行php artisan config:cache命令,则应确保只从配置文件中调用env()函数。 显然我在配置文件之外有env变量,所以在缓存之后我再也无法在外面使用它了。 php artisan config:clear让它重新投入使用。 我发现更多关于env的用法,它只能在配置文件中使用。 您可以使用其他帮助程序方法config()从项目的其 ...
-
当然,我自己也倾向于每次都“弯曲”一个框架,总有一种方法,但并不总是最好的解决方案。 我并没有在这里给出一个完整的实现,只是指出你的方向,这可能对你有用。 您可以扩展Laravel的基本应用程序类Illuminate\Foundation\Application ,其中包含在应用程序引导期间加载的$environmentFile变量存储环境文件,或者可能覆盖函数loadEnvironmentFrom($file)或environmentFile() 。 整个逻辑取决于你。 所以基本上你需要做的只是为了能够使 ...
-
如何在Laravel 5.1 TestCase中访问.env中的值(How do I access values from .env in Laravel 5.1 TestCase)[2022-07-21]
启动Dotenv以在TestCase阶段获得.env变量 public function createApplication() { $app = require __DIR__.'/../bootstrap/app.php'; $app->make('Illuminate\Contracts\Console\Kernel')->bootstrap(); Dotenv::load(__DIR__.'/../'); $this->baseUrl = env('APP_URL' ... -
没有.env文件的命令行生成中的Laravel和环境变量(Laravel and environment variables in command line production without .env file)[2021-11-25]
我一直认为.env文件只是设置服务器的一部分。 git会忽略.env文件,所以一旦设置完毕,你可以推送/拉动你内心的内容,它会单独保留.env文件。 到目前为止,至少我是如何做到的。 I always thought that the .env file was just part of setting up your server. The .env file is ignored by git, so once it's setup, you can push/pull to your heart's ... -
您可以将APP_ENV环境变量转储到托管JavaScript的页面,稍后访问它或将其传递给Vue。 然后在你的控制器中... $env = getenv("APP_ENV"); 会让你获得APP_ENV的价值 You could dump the APP_ENV environment variable to the page hosting your JavaScr ...
-
宝石提供了一个发电机: $ rails generate figaro:install 生成器创建一个config / application.yml文件并修改.gitignore文件以防止将文件检入到git存储库中。 您可以将环境变量作为键/值对添加到config / application.yml中 : GMAIL_USERNAME: Your_Username 环境变量将作为ENV变量在您的应用程序中的任何位置可用: ENV["GMAIL_USERNAME"] 这为您提供了在代码中使用相同变量的 ...
-
Laravel Artisan - 重新加载.env变量或重启框架(Laravel Artisan - reload .env variables or restart framework)[2022-05-21]
Laravel使用配置文件从.env文件中获取数据。 因此,您可以做的是在运行时覆盖配置值 : config(['database.default' => 'mysql']); Laravel uses config files which take data from .env file. So, what you can do is to override configuration values at runtime: config(['database.default' => 'mysql']); ... -
每个单独的命令(前缀为- )都在自己的shell中运行。 这就是您获取的环境变量在以下命令中不存在的原因。 我看到有三种方式: 1)在circle.yml定义环境变量。 我知道你说你不想这样做,但这是迄今为止最简单,最明确的方法。 2)您可以使用source命令为需要变量的行添加前缀。 例如: test: override: - source ./config/test_config.sh; nvm use 7.9 && npm test 3)利用多线YAML: test: overrid ...
-
您无法从angular读取.env文件,因为此文件不公开,客户端显然无法访问。 要公开一些后端配置,您有一些替代方案: 暴露配置api,在应用程序准备就绪时通过$ http调用它(使用.run())并将检索到的数据保存在服务中,以便您可以在前端组件之间共享配置 创建一个后端服务,该服务呈现为js文件,并将此js文件包含为标准角度组件 在ng-app节点上使用服务器定义的ng-init,以便通过角度范围访问配置 在我看来,第一个是最好的。 You cannot read .env files from ang ...