duandian2725 2014-12-29 05:09
浏览 5

插入数据有效,但无法使用YiiMongoDB Suite从MongoDB中检索数据

First off I know the developer stopped working on this extension full time, but from what I understand there are still alot of people using it. Hoping someone can help me with this (hopefully simple problem!)

I'm trying to read the data I just inserted into MongoDB using the YiiMongoDbSuite extension.

The data is successfully inserted as I can see it via the mongo console.

The problem is when I try to retrieve it. Here's the code I'm running together - it inserts it (no problem), but can't retrieve it:

<?php

$new = new Character();
$new->playerName = "Yii-Insert-Test";
$new->playerId = "123456789";
$new->playerScore = "9001";
$new->save();

$findAll = Character::model()->findAll();
foreach($findAll as $result) {
echo $result->playerName; // result should be "Yii-Insert-Test", instead it's NULL
}

?>

It does get inserted though:

{
"_id" : ObjectId("54a0deda60fc21843100002a"),
"playerName" : "Yii-Insert-Test",
"playerId" : "123456789",
"playerScore" : "9001"
}

And here's my very simple model Character.php :

<?php

class Character extends EMongoDocument
{

public $_id;
public $playerName;
public $playerId;
public $playerScore;


public function getCollectionName()
{
    return 'usercollection';
}

public function rules()
{
    return array(
        array('playerName', 'required'),
    );
}

public function attributeNames()
{
    return array(
        'playerName' => 'Character Name',
        'playerId' => 'Character ID',
        'playerScore' => 'Character Score',
    );
}

public static function model($className=__CLASS__)
  {
    return parent::model($className);
  }
}

I feel like it's right in front of me but can't see what the problem is.

edit:

slowly figuring it out - looks like I am receiving data, but it's all empty - this is the mongoDB cursor. I'm already doing a forloop to iterate it, so I'll have to figure out what else I'm not doing.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒