File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -110,8 +110,11 @@ PHP_METHOD(WriteBatch, insert)
110
110
111
111
if (bson_iter_init_find (& iter , bson_out , "_id" )) {
112
112
php_phongo_objectid_new_from_oid (return_value , bson_iter_oid (& iter ) TSRMLS_CC );
113
+ bson_clear (& bson_out );
113
114
return ;
114
115
}
116
+
117
+ bson_clear (& bson_out );
115
118
}
116
119
}
117
120
/* }}} */
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ MongoDB\Write\Batch: #002 Get the generated ID
3
+ --SKIPIF--
4
+ <?php require "tests/utils/basic-skipif.inc " ?>
5
+ --FILE--
6
+ <?php
7
+ require_once "tests/utils/basic.inc " ;
8
+
9
+ $ mm = new MongoDB \Manager (MONGODB_URI );
10
+
11
+ $ hannes = array ("name " => "Hannes " , "country " => "USA " , "gender " => "male " );
12
+ $ hayley = array ("name " => "Hayley " , "country " => "USA " , "gender " => "female " );
13
+ $ ordered = true ;
14
+
15
+ $ insertBatch = new \MongoDB \WriteBatch ($ ordered );
16
+ $ hannes_id = $ insertBatch ->insert ($ hannes );
17
+ $ hayley_id = $ insertBatch ->insert ($ hayley );
18
+
19
+ $ w = 1 ;
20
+ $ wtimeout = 1000 ;
21
+ $ writeConcern = new \MongoDB \WriteConcern ($ w , $ wtimeout );
22
+ $ result = $ mm ->executeWriteBatch ("db.collection " , $ insertBatch , $ writeConcern );
23
+
24
+ assert ($ result instanceof \MongoDB \WriteResult);
25
+
26
+ printf (
27
+ "Inserted %d documents to %s \n" ,
28
+ $ result ->getNumInserted (),
29
+ $ result ->getServer ()->getHost ()
30
+ );
31
+ printf ("hannes: %s \nhayley: %s \n" , $ hannes_id , $ hayley_id );
32
+ ?>
33
+ ===DONE===
34
+ <?php exit (0 ); ?>
35
+ --EXPECTF--
36
+ Inserted 2 documents to localhost
37
+ hannes: %s
38
+ hayley: %s
39
+ ===DONE===
You can’t perform that action at this time.
0 commit comments