我在查询我的mongoDB时尝试使用排序功能,但它失败了.相同的查询在MongoDB控制台中有效但在此处不起作用.代码如下:
import pymongo
from pymongo import Connection
connection = Connection()
db = connection.myDB
print db.posts.count()
for post in db.posts.find({}, {'entities.user_mentions.screen_name':1}).sort({u'entities.user_mentions.screen_name':1}):
print post
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
Traceback (most recent call last):
File "find_ow.py", line 7, in <module>
for post in db.posts.find({}, {'entities.user_mentions.screen_name':1}).sort({'entities.user_mentions.screen_name':1},1):
File "/Library/Python/2.6/site-packages/pymongo-2.0.1-py2.6-macosx-10.6-universal.egg/pymongo/cursor.py", line 430, in sort
File "/Library/Python/2.6/site-packages/pymongo-2.0.1-py2.6-macosx-10.6-universal.egg/pymongo/helpers.py", line 67, in _index_document
TypeError: first item in each key pair must be a string
Run Code Online (Sandbox Code Playgroud)
我在其他地方找到了一个链接,说如果使用pymongo,我需要放置一个'u'的钥匙,但这也不起作用.其他人让这个工作或这是一个错误.
我正在尝试使用PHPUnit测试我的symfony2应用程序.我有一个项目,其中一切都按预期工作,但在我的另一个项目中,我有这种奇怪的行为,PHPUnit在所有测试结束后随机停止执行Test Suite,并在完成Test Suite并编写代码后重新启动或重新启动测试覆盖.其他时候它正常运行.
这里有一些输出可以看到正在发生的事情(测试重复一遍又一遍):
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
...........PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
...PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
............PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from C:\workspace\cllctr\app\phpunit.xml
................................................................. 65 / 83 ( 78%)
.................. …Run Code Online (Sandbox Code Playgroud) 我有一个问题:在一个过程中,我想取消在prePersit函数中保存实体:
/**
* @ORM\PrePersist
*/
public function setTranslationsValue2()
{
if((null===$this->getContent())or($this->getContent()==''))
{
//wanna stop saving this item???
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的函数中,我不想再保存这个实体,并且不想停止我的进程(该进程仍然保存另一个s)
我很高兴使用fabric来部署我的Python项目.现在我参与了一个更大的PHP项目,并想知道是否有类似PHP的结构?
我在symfony2应用程序中使用内置SOAP-Server,在处理StdClass-Object之后,我需要读取收到的用于调试和记录的完整xml.有没有办法简单地捕获转移的xml?它应该在请求标题中的某个位置,但我根本找不到它.
在我的Symfony 2应用程序中,我想使用标准的用户和角色授权系统(http://symfony.com/doc/2.0/book/security.html)
我的用户是存储在具有doctrine(实现用户界面)的数据库中的实体.我将在我的系统中有5个预定义角色,每个用户可能有多个这些角色.
实现这一目标的最惯用方法是什么?我在考虑以下三种解决方案.
创建单独的Role实体并与用户实体创建多对多关系
在用户中有一个字段,它是一个排序的逗号分隔的角色列表,getRoles()实现为 explode(',',this.all_roles)
每个角色的用户实体中有5个二进制字段
实现这个系统最常用的方法是什么?
我正在尝试使用vagrant和默认的ubuntu 10.04 64位计算机将我的开发环境(symfony2应用程序)从我的Windows 7 localhost移动到虚拟机.一切都已建立,几乎可以运作,但有一件事困扰着我:
当我运行ant并执行phpunit时,我在执行自制引导时遇到以下错误:
stty: standard input: Invalid argument
Run Code Online (Sandbox Code Playgroud)
我可以将问题缩小到以下代码行,执行symfony cache:warmup命令:
executeCommand($application, "cache:warmup");
Run Code Online (Sandbox Code Playgroud)
这将执行以下命令:
php app/console -e test -q cache:warmup
Run Code Online (Sandbox Code Playgroud)
没有ant的运行phpunit工作正常,没有executeCommand行运行ant也是如此.
我读了一些关于这个stty的错误,抬头~/.bashrc,~./profile,/etc/bash.bashrc,/etc/profile以及/root/.bashrc和/root/.profile没有找到像TTY或stty的东西.所以我不知道我可以删除什么使它工作.
我有点卡住,因为我需要缓存预热,无法弄清楚出了什么问题.
我有一个symfony2应用程序,我正在使用phpunit.
我有一些单元测试,我使用模拟来模拟AppKernel和功能测试,这些测试向应用程序发出"真正的"请求.单独运行单元测试或功能测试时,一切正常.
当我想立刻运行所有测试时,它会变得很糟糕.单元测试完成后,phpunit就会停止,告诉我:
Fatal error: Cannot redeclare class AppKernel in C:\Users\sebastian\workspace\ppInterface\app\AppKernel.php on line 35
我不明白这一点,因为我认为phpunit会在它自己的环境中运行每个测试.情况似乎并非如此.我能做些什么来使事情正确并"重置"测试运行的环境?
我无法让symfony2配置正确覆盖其他配置文件中的值.这是问题所在:
我有一个新的环境"staging"我想要使用来自config_prod.yml的大部分内容但是有另一个日志记录级别(我希望它在开发中,只需将所有内容记录到文件中).这是我使用的配置内容:
config_prod.yml:
imports:
- { resource: config.yml }
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
Run Code Online (Sandbox Code Playgroud)
config_staging.yml:
imports:
- { resource: config_prod.yml }
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
nested: ~
Run Code Online (Sandbox Code Playgroud)
从我的角度来看,嵌套记录器现在为null,主记录到给定文件.真正发生的是他将每条消息记录两次!当我将它用于config_staging.yml时也会发生同样的情况:
imports:
- { resource: config_prod.yml }
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
handler: ~
nested: ~
Run Code Online (Sandbox Code Playgroud)
我找到了一个解决方法,将主处理程序的action_level设置为debug并将其他所有内容保留原样,但我不喜欢这个解决方案.必须有一种方法来覆盖配置的东西,所以我只有主要的monolog处理程序.
我想使用symfony2为我的应用程序创建一个状态页面,我想打印特定请求的执行时间(以及其他数据).无论如何我都找不到这样做.
我知道我可以跟踪代码部分的执行时间:
$starttime = microtime();
// do something
$duration = microtime() - $starttime;
Run Code Online (Sandbox Code Playgroud)
但由于显而易见的原因,我不能将它放在控制器中,因为整个引导程序都不会被跟踪.也不包括渲染模板.
有没有办法尽可能接近脚本的总执行时间?