1
0
mirror of https://github.com/php/doc-es.git synced 2026-03-26 00:12:06 +01:00
Files
archived-doc-es/reference/mongo/writes.xml
Pedro Antonio Gil Rodríguez 48db252cf2 Actualización a la última versión
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@334831 c90b9560-bf6c-de11-be94-00142212c4b1
2014-09-10 08:34:08 +00:00

93 lines
2.2 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 565e478d69a9d0c217eda773c77ca823423adf21 Maintainer: seros Status: ready -->
<!-- Reviewed: yes Maintainer: seros -->
<chapter xml:id="mongo.writes" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Escrituras</title>
<section>
<title>Actualización de objetos anidados</title>
<para>
Supongamos que queremos cambiar el nombre del autor de un comentario en este documento:
<programlisting role="javascript">
<![CDATA[
{
"_id" : ObjectId("4b06c282edb87a281e09dad9"),
"content" : "this is a blog post.",
"comments" :
[
{
"author" : "Mike",
"comment" : "I think that blah blah blah...",
},
{
"author" : "John",
"comment" : "I disagree."
}
]
}
]]>
</programlisting>
Para cambiar un campo interno usamos $set (de manera que el resto de campos no
se eliminen) con el índice del comentario a cambiar:
<programlisting role="php">
<![CDATA[
<?php
$blog->update($criteria, array('$set' => array("comments.1" => array("author" => "Jim"))));
?>
]]>
</programlisting>
</para>
</section>
<section>
<title>El operador posicional</title>
<para>
El operador posicional <literal>$</literal> es útil a la hora de actualizar objetos
de arrays. En el ejemplo anterior, por ejemplo, podríamos no conocer el índice del
comentario que necesitamos modificar; sólo sabemos que queremos cambiar "John" a "Jim".
Podemos usar <literal>$</literal> para lograrlo.
</para>
<programlisting role="php">
<![CDATA[
<?php
$blog->update(
array("comments.author" => "John"),
array('$set' => array('comments.$.author' => "Jim")));
?>
]]>
</programlisting>
</section>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->