<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 22:01:24 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CXX-1100] Having more than one iterator per cursor violates mongoc lifecycle constraints</title>
                <link>https://jira.mongodb.org/browse/CXX-1100</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;Given a single cursor, iterator construction and iteration result in the construction of &lt;tt&gt;bsoncxx::document::view&lt;/tt&gt; objects wrapping the &lt;tt&gt;bson_t&lt;/tt&gt; pointer returned by a call to &lt;tt&gt;mongoc_cursor_next&lt;/tt&gt;.  However, the validity of this &lt;tt&gt;bson_t&lt;/tt&gt; pointer is only until the next call to &lt;tt&gt;mongoc_cursor_next&lt;/tt&gt; (see &lt;a href=&quot;http://mongoc.org/libmongoc/current/mongoc_cursor_next.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;docs&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Consider this example:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;auto cursor = db[&quot;fo&quot;].find({});&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;auto iter1 = cursor.begin();  // Calls mongoc_cursor_next().&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;auto iter2 = cursor.begin();  // Calls mongoc_cursor_next().&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// At this point, iter1._doc violates the lifecycle constraints.&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;iter1++;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&amp;nbsp;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// At this point, iter2._doc violates the lifecycle constraints.&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;In short, only the most recently iterated iterator ever has a valid &lt;tt&gt;bsoncxx::document::view&lt;/tt&gt;.&lt;/p&gt;</description>
                <environment></environment>
        <key id="326488">CXX-1100</key>
            <summary>Having more than one iterator per cursor violates mongoc lifecycle constraints</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="david.golden@mongodb.com">David Golden</assignee>
                                    <reporter username="david.golden@mongodb.com">David Golden</reporter>
                        <labels>
                    </labels>
                <created>Mon, 24 Oct 2016 21:21:09 +0000</created>
                <updated>Tue, 13 Dec 2016 16:48:30 +0000</updated>
                            <resolved>Tue, 15 Nov 2016 20:39:45 +0000</resolved>
                                                    <fixVersion>3.1.0</fixVersion>
                                    <component>Implementation</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="1445016" author="xgen-internal-githook" created="Tue, 29 Nov 2016 18:50:23 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;xdg&apos;, u&apos;name&apos;: u&apos;David Golden&apos;, u&apos;email&apos;: u&apos;xdg@xdg.me&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; Fix mongocxx cursor iteration&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; reported the repeated calls to mongocxx::cursor::begin() would&lt;br/&gt;
increment the cursor and lose documents.  This is fixed by only&lt;br/&gt;
incrementing the cursor during construction one time (required to send the&lt;br/&gt;
query/command to the server).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; reported that incrementing an iterator would leave all other&lt;br/&gt;
iterators on that cursor with dangling pointers.  While this is&lt;br/&gt;
technically legal, if undefined behavior, for input iterators, the team&lt;br/&gt;
decided to have all iterators from the same cursor move in lockstep;&lt;br/&gt;
this is also legal and prevents undefined behaviors, which is more&lt;br/&gt;
user-friendly.  This is achieved by moving the &quot;current document&quot; view&lt;br/&gt;
into the private cursor implementation rather than keeping copies in&lt;br/&gt;
individual iterators.&lt;/p&gt;

&lt;p&gt;The changes above required some additional coordination to track cursors&lt;br/&gt;
sent and dead/finished.  Strangely, we couldn&apos;t depend on libmongoc&lt;br/&gt;
functions for this due to what appear to be some inconsistencies in&lt;br/&gt;
libmongoc&apos;s handling of &quot;traditional&quot; cursors and &quot;command cursors&quot;.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1445014" author="xgen-internal-githook" created="Tue, 29 Nov 2016 18:50:20 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;xdg&apos;, u&apos;name&apos;: u&apos;David Golden&apos;, u&apos;email&apos;: u&apos;xdg@xdg.me&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; Fix mongocxx cursor iteration&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; reported the repeated calls to mongocxx::cursor::begin() would&lt;br/&gt;
increment the cursor and lose documents.  This is fixed by only&lt;br/&gt;
incrementing the cursor during construction one time (required to send the&lt;br/&gt;
query/command to the server).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; reported that incrementing an iterator would leave all other&lt;br/&gt;
iterators on that cursor with dangling pointers.  While this is&lt;br/&gt;
technically legal, if undefined behavior, for input iterators, the team&lt;br/&gt;
decided to have all iterators from the same cursor move in lockstep;&lt;br/&gt;
this is also legal and prevents undefined behaviors, which is more&lt;br/&gt;
user-friendly.  This is achieved by moving the &quot;current document&quot; view&lt;br/&gt;
into the private cursor implementation rather than keeping copies in&lt;br/&gt;
individual iterators.&lt;/p&gt;

&lt;p&gt;The changes above required some additional coordination to track cursors&lt;br/&gt;
sent and dead/finished.  Strangely, we couldn&apos;t depend on libmongoc&lt;br/&gt;
functions for this due to what appear to be some inconsistencies in&lt;br/&gt;
libmongoc&apos;s handling of &quot;traditional&quot; cursors and &quot;command cursors&quot;.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1434932" author="xgen-internal-githook" created="Tue, 15 Nov 2016 20:38:46 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;xdg&apos;, u&apos;name&apos;: u&apos;David Golden&apos;, u&apos;email&apos;: u&apos;xdg@xdg.me&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; Fix mongocxx cursor iteration&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; reported the repeated calls to mongocxx::cursor::begin() would&lt;br/&gt;
increment the cursor and lose documents.  This is fixed by only&lt;br/&gt;
incrementing the cursor during construction one time (required to send the&lt;br/&gt;
query/command to the server).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; reported that incrementing an iterator would leave all other&lt;br/&gt;
iterators on that cursor with dangling pointers.  While this is&lt;br/&gt;
technically legal, if undefined behavior, for input iterators, the team&lt;br/&gt;
decided to have all iterators from the same cursor move in lockstep;&lt;br/&gt;
this is also legal and prevents undefined behaviors, which is more&lt;br/&gt;
user-friendly.  This is achieved by moving the &quot;current document&quot; view&lt;br/&gt;
into the private cursor implementation rather than keeping copies in&lt;br/&gt;
individual iterators.&lt;/p&gt;

&lt;p&gt;The changes above required some additional coordination to track cursors&lt;br/&gt;
sent and dead/finished.  Strangely, we couldn&apos;t depend on libmongoc&lt;br/&gt;
functions for this due to what appear to be some inconsistencies in&lt;br/&gt;
libmongoc&apos;s handling of &quot;traditional&quot; cursors and &quot;command cursors&quot;.&lt;br/&gt;
Branch: 3.1-dev&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1434930" author="xgen-internal-githook" created="Tue, 15 Nov 2016 20:38:45 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;xdg&apos;, u&apos;name&apos;: u&apos;David Golden&apos;, u&apos;email&apos;: u&apos;xdg@xdg.me&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; Fix mongocxx cursor iteration&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; reported the repeated calls to mongocxx::cursor::begin() would&lt;br/&gt;
increment the cursor and lose documents.  This is fixed by only&lt;br/&gt;
incrementing the cursor during construction one time (required to send the&lt;br/&gt;
query/command to the server).&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1100&quot; title=&quot;Having more than one iterator per cursor violates mongoc lifecycle constraints&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1100&quot;&gt;&lt;del&gt;CXX-1100&lt;/del&gt;&lt;/a&gt; reported that incrementing an iterator would leave all other&lt;br/&gt;
iterators on that cursor with dangling pointers.  While this is&lt;br/&gt;
technically legal, if undefined behavior, for input iterators, the team&lt;br/&gt;
decided to have all iterators from the same cursor move in lockstep;&lt;br/&gt;
this is also legal and prevents undefined behaviors, which is more&lt;br/&gt;
user-friendly.  This is achieved by moving the &quot;current document&quot; view&lt;br/&gt;
into the private cursor implementation rather than keeping copies in&lt;br/&gt;
individual iterators.&lt;/p&gt;

&lt;p&gt;The changes above required some additional coordination to track cursors&lt;br/&gt;
sent and dead/finished.  Strangely, we couldn&apos;t depend on libmongoc&lt;br/&gt;
functions for this due to what appear to be some inconsistencies in&lt;br/&gt;
libmongoc&apos;s handling of &quot;traditional&quot; cursors and &quot;command cursors&quot;.&lt;br/&gt;
Branch: 3.1-dev&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-cxx-driver/commit/e2c086fe158c9a21f1d168ec13800b1a04e2211f&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1429939" author="david.golden" created="Wed, 9 Nov 2016 04:14:38 +0000"  >&lt;p&gt;&lt;a href=&quot;https://mongodbcr.appspot.com/107340001/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mongodbcr.appspot.com/107340001/&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1419849" author="rassi@10gen.com" created="Thu, 27 Oct 2016 19:46:27 +0000"  >&lt;p&gt;Oh, yes, that&apos;s true!  I like that.  If we do end up removing begin()/end() and go with recommending that route, we should also provide some supporting non-lambda example code, for users who aren&apos;t comfortable with using lambdas.&lt;/p&gt;</comment>
                            <comment id="1419630" author="david.golden" created="Thu, 27 Oct 2016 16:51:05 +0000"  >&lt;p&gt;Another option would be letting people use &lt;a href=&quot;http://en.cppreference.com/w/cpp/algorithm/for_each&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;std::for_each&lt;/a&gt; and a lambda.&lt;/p&gt;</comment>
                            <comment id="1419613" author="rassi@10gen.com" created="Thu, 27 Oct 2016 16:31:57 +0000"  >&lt;p&gt;Here&apos;s a proposal for syntactic sugar we could provide to possibly replace range-for loops for cursor iteration:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;cursor::iterator it(some_cursor);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: #006699; font-weight: bold; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;while&lt;/span&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt; (auto doc = our_sugar_function(&amp;amp;it)) {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    &lt;/span&gt;&lt;span style=&quot;color: #008200; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;// &quot;doc&quot; is of type stdx::optional&amp;lt;document::view&amp;gt;.&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;</comment>
                            <comment id="1417904" author="david.golden" created="Wed, 26 Oct 2016 10:45:29 +0000"  >&lt;p&gt;I chatted with Dana yesterday about these issues and his thoughts were more or less as follows:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;begin()/end() is an expectation users will have; they&apos;ll want it for STL algorithms/templates.&lt;/li&gt;
	&lt;li&gt;begin() shouldn&apos;t advance the cursor; it made sense to him to have begin() get the first document only if the query wasn&apos;t sent and otherwise just return the current document.&lt;/li&gt;
	&lt;li&gt;He liked the idea of moving _doc into the cursor object; since it&apos;s a view on the buffer of the unique implementation, keeping it with the implementation avoids lifetime issues.&lt;/li&gt;
	&lt;li&gt;He didn&apos;t like the idea of throwing exceptions at runtime (e.g. calling begin() twice).&lt;/li&gt;
	&lt;li&gt;He didn&apos;t think we should have begin() run the query again&lt;/li&gt;
	&lt;li&gt;He was open to the idea of a &quot;clone&quot; method on the cursor for users who really needed to iterate from the start again.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;In response to other comments, my own thoughts:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;We agreed in &lt;a href=&quot;https://jira.mongodb.org/browse/CXX-1001&quot; title=&quot;mongocxx::cursor.begin() increments the iterator&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CXX-1001&quot;&gt;&lt;del&gt;CXX-1001&lt;/del&gt;&lt;/a&gt; to keep begin()/end(); I&apos;d like to stick to that rather than repeat the arguments a second time because I don&apos;t think we&apos;ll arrive at a different conclusion.&lt;/li&gt;
	&lt;li&gt;Looking at &lt;a href=&quot;http://en.cppreference.com/w/cpp/concept/InputIterator&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;InputIterator&lt;/a&gt;, nothing forbids us from having all iterators stay &quot;in sync&quot; on the current document in the implementation.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Therefore, I think building on idea #1 is simple to implement and explain and addresses all the needs we have:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Move _doc to mongocxx::cursor&lt;/li&gt;
	&lt;li&gt;mongocxx::cursor::iterator construction from mongocxx::cursor no longer advances the libmongoc cursor; it merely sets its _cursor pointer&lt;/li&gt;
	&lt;li&gt;begin() advances the cursor only if the query has not yet executed; this requires adding a &lt;tt&gt;started_&lt;/tt&gt; boolean or equivalent to mongocxx::cursor as there appears to be no way to get this from libmongoc&apos;s cursor API&lt;/li&gt;
	&lt;li&gt;dereferencing any iterator always returns the _doc via the iterators cursor pointer&lt;/li&gt;
	&lt;li&gt;incrementing any iterator always increments the libmongoc cursor and updates _doc in the cursor object&lt;/li&gt;
&lt;/ul&gt;
</comment>
                            <comment id="1417427" author="rassi@10gen.com" created="Tue, 25 Oct 2016 20:40:50 +0000"  >&lt;blockquote&gt;
&lt;p&gt;Depending on the choice, we should probably also consider disallowing copy construction of cursor iterators.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;I don&apos;t think we should.  In order for cursor::iterator to satisfy InputIterator, it must satisfy Iterator.  For a type to satisfy Iterator, it must be copy-constructible and copy-assignable (see &lt;a href=&quot;http://en.cppreference.com/w/cpp/concept/Iterator&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://en.cppreference.com/w/cpp/concept/Iterator&lt;/a&gt;).&lt;/p&gt;</comment>
                            <comment id="1417022" author="rassi@10gen.com" created="Tue, 25 Oct 2016 16:13:54 +0000"  >&lt;p&gt;My vote would be for the following (somewhat equivalent to #3 above):&lt;br/&gt;
1) For the next 3.0.x release, make cursor::begin() throw an exception if it&apos;s called twice, or at least document it as invalid to call twice.&lt;br/&gt;
2) For either 3.1 or 4.0, remove cursor::begin() and cursor::end() entirely.  In my opinion, they make it too easy for novice users to shoot themselves in the foot.&lt;/p&gt;

&lt;p&gt;I don&apos;t think of the above as limiting at all.  cursor::iterator is an InputIterator, and you can pass it to any algorithm that takes an InputIterator.  I think that trying to fake ForwardIterator functionality for cursor::iterator is a bad idea.&lt;/p&gt;

&lt;p&gt;To assist users who are less familiar with the details of the InputIterator concept, we could also put a note in the class comment for cursor::iterator which reminds users that incrementing the iterator invalidates all copies of that iterator.&lt;/p&gt;</comment>
                            <comment id="1416231" author="david.golden" created="Mon, 24 Oct 2016 21:28:19 +0000"  >&lt;p&gt;Brainstorming possible solutions:&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;Keep _doc in the cursor object and have iterators access it via the cursor object.  This means all iterators are just API aliases of the cursor object.  &lt;tt&gt;iter1&lt;/tt&gt; and &lt;tt&gt;iter2&lt;/tt&gt; always refer to the same document, regardless of which one was incremented last.&lt;/li&gt;
	&lt;li&gt;Put a &lt;tt&gt;stdx::optional&amp;lt;cursor::iterator&amp;gt;&lt;/tt&gt; in the cursor object.  Construct it once and return references to it for &lt;tt&gt;begin()&lt;/tt&gt;.  Like #1, this means all iterators are just aliases of the &quot;singleton&quot; iterator for the cursor.&lt;/li&gt;
	&lt;li&gt;Make getting a second iterator from a cursor fatal (this is probably quite limiting).&lt;/li&gt;
	&lt;li&gt;Have &lt;tt&gt;begin()&lt;/tt&gt; clone the underlying &lt;tt&gt;mongoc_cursor_t&lt;/tt&gt; and execute a separate query.  This makes &lt;tt&gt;begin()&lt;/tt&gt; idempotent, but repeated use expensive.&lt;/li&gt;
	&lt;li&gt;Copy documents into iterators so their lifecycles are independent.  (Safe but slow.)&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Depending on the choice, we should probably also consider disallowing copy construction of cursor iterators.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="310644">CXX-1001</issuekey>
        </issuelink>
            <issuelink>
            <issuekey id="326924">CDRIVER-1886</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10012"><![CDATA[Major Change]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrc36n:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="1351">Perl/CXX 2016-11-11</customfieldvalue>
    <customfieldvalue id="1392">Perl/CXX 2016-12-02</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>