com presentations: Add MongoCollection::remove() example: mongo-tut-tek15.xml slides/mongodb/remove.xml

[email protected] (Derick Rethans)
Newsgroups php.pres
Message-ID <[email protected]>
Commit:    2ecb53447c2662882c60817c996c64d64ba0792f
Author:    Jeremy Mikola <[email protected]>         Sun, 17 May 2015 15:30:45 -0500
Parents:   613a7ed41708c6182aa15278fbfc1a546dbf3eae
Branches:  master

Link:       http://git.php.net/?p=presentations.git;a=commitdiff;h=2ecb53447c2662882c60817c996c64d64ba0792f

Log:
Add MongoCollection::remove() example

Changed paths:
  M  mongo-tut-tek15.xml
  A  slides/mongodb/remove.xml


Diff:
diff --git a/mongo-tut-tek15.xml b/mongo-tut-tek15.xml
index 5cc047a..45de045 100644
--- a/mongo-tut-tek15.xml
+++ b/mongo-tut-tek15.xml
@@ -70,6 +70,7 @@
 
 
 <slide>slides/mongodb/update2a.xml</slide>
+<slide>slides/mongodb/remove.xml</slide>
 
 <!-- SCHEMA DESIGN -->
 <slide>slides/mongodb/section-schema-design.xml</slide>
diff --git a/slides/mongodb/remove.xml b/slides/mongodb/remove.xml
new file mode 100644
index 0000000..990ea04
--- /dev/null
+++ b/slides/mongodb/remove.xml
@@ -0,0 +1,22 @@
+<slide>
+<title>Deleting documents</title>
+
+<blurb>Unlike %update%, %remove% deletes *all* matched documents by default.</blurb>
+
+<blurb>You can set an option to remove only the *first* matched document</blurb>
+
+<example result="0"><![CDATA[<?php
+$m = new MongoClient;
+$c = $m->demo->products;
+$c->drop();
+
+$c->insert( [ '_id' => 'blue-elephpant',  'generation' => 1, 'price' => 7.5 ] );
+$c->insert( [ '_id' => 'pink-elephpant',  'generation' => 2, 'price' => 8.0 ] );
+$c->insert( [ '_id' => 'green-elephpant', 'generation' => 3, 'price' => 7.5 ] );
+
+$c->remove(
+    [ 'price' => [ '$lt' => 8.0 ] ],  // criteria
+    [ 'justOne' => true ]             // options: justOne
+);
+?>]]></example>
+</slide>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.