There is no way to do this with
YMDS. You can easily do whatever you want with the native PHP
MongoCollection object, like:
User::model()->getCollection()->update(
array('addresses.city' => 'My City'),
array('$set' => array('addesses.$.city' => 'New
York')),
array('multiple' => true)
);
Not tested, but it should work this way. In my
experience, MongoCollection seems to be the only choice.
2012-04-19
Zheng Gui
发件人: Riccardo Coppola
发送时间: 2012-04-19 17:38:49
收件人: yiimongodbsiute
抄送:
主题: [ymds] Update array of
EmbeddedDocument
Hi all,
I have a field in my collection that is an array of embedded
documents.
Now, I have to update an embedded document using one of it's properties as
key for the query
In short, I can't use
$user->addresses[0]->city =
'New York';
but i'd like to use something like
$user->addresses['city':
'MyCity']->city = 'New York';
To update the embedded document with city = 'MyCity' with the new value
'New York'.
In mongo shell, i'd use the $ positional operator this way:
t.update( {'adresses.city':'MyCity'}, {$set:{'addresses.$.city': 'New York'}})
Is there a way to do it with YiiMongoDbSuite?
Thank you,
Riccardo