0

私は問題があります。私はmongodbにこのdbの構造を持っています:

id:"xxx",
is_validated: "xxx",
validation_code:"xxx",
profile:[
{
        profile_pic:"xxx",
    firstname:"xxx",
    lastname:"xxx",
}
]

私はケーキphpを使用しています。レコードを更新するときは、これを使用します。

$this->User->set('id', "xxx");
$this->User->set('profile', array('firstname' => 'Benedict'));
$this->User->save()

レコードを保存すると、プロファイルの配列全体が削除され、「名」のみが保存されます。

id:"xxx",
is_validated: "xxx",
validation_code:"xxx",
profile:[
{
    firstname:"xxx"
}
]

Cakephp を使用して、mongodb の他の配列レコードを削除せずに名を保存できるようにする必要があります。

4

2 に答える 2

1

MongoDB を使用する場合、標準的な規則に従っていませんか? (ドキュメント):

// where '1' is the id of your user    
$this->User->read(null, 1);
// set the new value for the field
$this->User->set('profile', array('firstname' => 'Benedict'));
// commit the changes to the database
$this->User->save();

アップデート

上記が機能しない場合は、レコード全体を読み取り、それに応じて変更してみてください。

// set the active record
$this->User->id = 1;
// read the entire record
$user = $this->User->read();
// modify the field
$user['User']['profile']['firstname'] = 'Benedict';
// save the record
$this->User->save($user);
于 2013-05-08T11:11:25.147 に答える
0

これが発生する理由は、渡す配列でプロファイル フィールドを更新するように要求しているためです。これにより、現在のプロファイル配列が適切に置き換えられます。

これを回避するには、保持したいキーとその値、および変更したいキーを含む完全な配列を渡す必要があります。

于 2013-05-08T10:45:16.213 に答える