/usr/share/doc/python-pymongo-doc/html/python3.html is in python-pymongo-doc 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Python 3 FAQ — PyMongo 3.4.0 documentation</title>
<link rel="stylesheet" href="_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '3.4.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/sidebar.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="top" title="PyMongo 3.4.0 documentation" href="index.html" />
<link rel="up" title="Changelog" href="changelog.html" />
<link rel="next" title="PyMongo 3 Migration Guide" href="migrate-to-pymongo3.html" />
<link rel="prev" title="Changelog" href="changelog.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="migrate-to-pymongo3.html" title="PyMongo 3 Migration Guide"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="changelog.html" title="Changelog"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">PyMongo 3.4.0 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="changelog.html" accesskey="U">Changelog</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="python-3-faq">
<h1><a class="toc-backref" href="#id1">Python 3 FAQ</a><a class="headerlink" href="#python-3-faq" title="Permalink to this headline">¶</a></h1>
<div class="contents topic" id="contents">
<p class="topic-title first">Contents</p>
<ul class="simple">
<li><a class="reference internal" href="#python-3-faq" id="id1">Python 3 FAQ</a><ul>
<li><a class="reference internal" href="#what-python-3-versions-are-supported" id="id2">What Python 3 versions are supported?</a></li>
<li><a class="reference internal" href="#are-there-any-pymongo-behavior-changes-with-python-3" id="id3">Are there any PyMongo behavior changes with Python 3?</a></li>
<li><a class="reference internal" href="#why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3" id="id4">Why can’t I share pickled ObjectIds between some versions of Python 2 and 3?</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="what-python-3-versions-are-supported">
<h2><a class="toc-backref" href="#id2">What Python 3 versions are supported?</a><a class="headerlink" href="#what-python-3-versions-are-supported" title="Permalink to this headline">¶</a></h2>
<p>PyMongo supports CPython 3.3+ and PyPy3.</p>
</div>
<div class="section" id="are-there-any-pymongo-behavior-changes-with-python-3">
<h2><a class="toc-backref" href="#id3">Are there any PyMongo behavior changes with Python 3?</a><a class="headerlink" href="#are-there-any-pymongo-behavior-changes-with-python-3" title="Permalink to this headline">¶</a></h2>
<p>Only one intentional change. Instances of <code class="xref py py-class docutils literal"><span class="pre">bytes</span></code>
are encoded as BSON type 5 (Binary data) with subtype 0.
In Python 3 they are decoded back to <code class="xref py py-class docutils literal"><span class="pre">bytes</span></code>. In
Python 2 they will be decoded to <a class="reference internal" href="api/bson/binary.html#bson.binary.Binary" title="bson.binary.Binary"><code class="xref py py-class docutils literal"><span class="pre">Binary</span></code></a>
with subtype 0.</p>
<p>For example, let’s insert a <code class="xref py py-class docutils literal"><span class="pre">bytes</span></code> instance using Python 3 then
read it back. Notice the byte string is decoded back to <code class="xref py py-class docutils literal"><span class="pre">bytes</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Python</span> <span class="mf">3.3</span><span class="o">.</span><span class="mi">5</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Apr</span> <span class="mi">29</span> <span class="mi">2016</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">04</span><span class="p">:</span><span class="mi">32</span><span class="p">)</span>
<span class="p">[</span><span class="n">GCC</span> <span class="mf">4.9</span><span class="o">.</span><span class="mi">3</span><span class="p">]</span> <span class="n">on</span> <span class="n">linux</span>
<span class="n">Type</span> <span class="s2">"help"</span><span class="p">,</span> <span class="s2">"copyright"</span><span class="p">,</span> <span class="s2">"credits"</span> <span class="ow">or</span> <span class="s2">"license"</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">>>></span> <span class="kn">import</span> <span class="nn">pymongo</span>
<span class="o">>>></span> <span class="n">c</span> <span class="o">=</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">MongoClient</span><span class="p">()</span>
<span class="o">>>></span> <span class="n">c</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">bintest</span><span class="o">.</span><span class="n">insert_one</span><span class="p">({</span><span class="s1">'binary'</span><span class="p">:</span> <span class="n">b</span><span class="s1">'this is a byte string'</span><span class="p">})</span><span class="o">.</span><span class="n">inserted_id</span>
<span class="n">ObjectId</span><span class="p">(</span><span class="s1">'4f9086b1fba5222021000000'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">c</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">bintest</span><span class="o">.</span><span class="n">find_one</span><span class="p">()</span>
<span class="p">{</span><span class="s1">'binary'</span><span class="p">:</span> <span class="n">b</span><span class="s1">'this is a byte string'</span><span class="p">,</span> <span class="s1">'_id'</span><span class="p">:</span> <span class="n">ObjectId</span><span class="p">(</span><span class="s1">'4f9086b1fba5222021000000'</span><span class="p">)}</span>
</pre></div>
</div>
<p>Now retrieve the same document in Python 2. Notice the byte string is decoded
to <a class="reference internal" href="api/bson/binary.html#bson.binary.Binary" title="bson.binary.Binary"><code class="xref py py-class docutils literal"><span class="pre">Binary</span></code></a>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Python</span> <span class="mf">2.7</span><span class="o">.</span><span class="mi">6</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Feb</span> <span class="mi">26</span> <span class="mi">2014</span><span class="p">,</span> <span class="mi">10</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">22</span><span class="p">)</span>
<span class="p">[</span><span class="n">GCC</span> <span class="mf">4.7</span><span class="o">.</span><span class="mi">3</span><span class="p">]</span> <span class="n">on</span> <span class="n">linux2</span>
<span class="n">Type</span> <span class="s2">"help"</span><span class="p">,</span> <span class="s2">"copyright"</span><span class="p">,</span> <span class="s2">"credits"</span> <span class="ow">or</span> <span class="s2">"license"</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">>>></span> <span class="kn">import</span> <span class="nn">pymongo</span>
<span class="o">>>></span> <span class="n">c</span> <span class="o">=</span> <span class="n">pymongo</span><span class="o">.</span><span class="n">MongoClient</span><span class="p">()</span>
<span class="o">>>></span> <span class="n">c</span><span class="o">.</span><span class="n">test</span><span class="o">.</span><span class="n">bintest</span><span class="o">.</span><span class="n">find_one</span><span class="p">()</span>
<span class="p">{</span><span class="s1">u'binary'</span><span class="p">:</span> <span class="n">Binary</span><span class="p">(</span><span class="s1">'this is a byte string'</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="s1">u'_id'</span><span class="p">:</span> <span class="n">ObjectId</span><span class="p">(</span><span class="s1">'4f9086b1fba5222021000000'</span><span class="p">)}</span>
</pre></div>
</div>
</div>
<div class="section" id="why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3">
<h2><a class="toc-backref" href="#id4">Why can’t I share pickled ObjectIds between some versions of Python 2 and 3?</a><a class="headerlink" href="#why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3" title="Permalink to this headline">¶</a></h2>
<p>Instances of <a class="reference internal" href="api/bson/objectid.html#bson.objectid.ObjectId" title="bson.objectid.ObjectId"><code class="xref py py-class docutils literal"><span class="pre">ObjectId</span></code></a> pickled using Python 2
can always be unpickled using Python 3.</p>
<p>If you pickled an ObjectId using Python 2 and want to unpickle it using
Python 3 you must pass <code class="docutils literal"><span class="pre">encoding='latin-1'</span></code> to pickle.loads:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Python</span> <span class="mf">2.7</span><span class="o">.</span><span class="mi">6</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Feb</span> <span class="mi">26</span> <span class="mi">2014</span><span class="p">,</span> <span class="mi">10</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">22</span><span class="p">)</span>
<span class="p">[</span><span class="n">GCC</span> <span class="mf">4.7</span><span class="o">.</span><span class="mi">3</span><span class="p">]</span> <span class="n">on</span> <span class="n">linux2</span>
<span class="n">Type</span> <span class="s2">"help"</span><span class="p">,</span> <span class="s2">"copyright"</span><span class="p">,</span> <span class="s2">"credits"</span> <span class="ow">or</span> <span class="s2">"license"</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">>>></span> <span class="kn">import</span> <span class="nn">pickle</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">bson.objectid</span> <span class="k">import</span> <span class="n">ObjectId</span>
<span class="o">>>></span> <span class="n">oid</span> <span class="o">=</span> <span class="n">ObjectId</span><span class="p">()</span>
<span class="o">>>></span> <span class="n">oid</span>
<span class="n">ObjectId</span><span class="p">(</span><span class="s1">'4f919ba2fba5225b84000000'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">oid</span><span class="p">)</span>
<span class="s1">'ccopy_reg</span><span class="se">\n</span><span class="s1">_reconstructor</span><span class="se">\n</span><span class="s1">p0</span><span class="se">\n</span><span class="s1">(cbson.objectid\...'</span>
<span class="n">Python</span> <span class="mf">3.3</span><span class="o">.</span><span class="mi">5</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Apr</span> <span class="mi">29</span> <span class="mi">2016</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">04</span><span class="p">:</span><span class="mi">32</span><span class="p">)</span>
<span class="p">[</span><span class="n">GCC</span> <span class="mf">4.9</span><span class="o">.</span><span class="mi">3</span><span class="p">]</span> <span class="n">on</span> <span class="n">linux</span>
<span class="n">Type</span> <span class="s2">"help"</span><span class="p">,</span> <span class="s2">"copyright"</span><span class="p">,</span> <span class="s2">"credits"</span> <span class="ow">or</span> <span class="s2">"license"</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">>>></span> <span class="kn">import</span> <span class="nn">pickle</span>
<span class="o">>>></span> <span class="n">pickle</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">b</span><span class="s1">'ccopy_reg</span><span class="se">\n</span><span class="s1">_reconstructor</span><span class="se">\n</span><span class="s1">p0</span><span class="se">\n</span><span class="s1">(cbson.objectid\...'</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s1">'latin-1'</span><span class="p">)</span>
<span class="n">ObjectId</span><span class="p">(</span><span class="s1">'4f919ba2fba5225b84000000'</span><span class="p">)</span>
</pre></div>
</div>
<p>If you need to pickle ObjectIds using Python 3 and unpickle them using Python 2
you must use <code class="docutils literal"><span class="pre">protocol</span> <span class="pre"><=</span> <span class="pre">2</span></code>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">Python</span> <span class="mf">3.3</span><span class="o">.</span><span class="mi">5</span> <span class="p">(</span><span class="n">default</span><span class="p">,</span> <span class="n">Apr</span> <span class="mi">29</span> <span class="mi">2016</span><span class="p">,</span> <span class="mi">11</span><span class="p">:</span><span class="mi">04</span><span class="p">:</span><span class="mi">32</span><span class="p">)</span>
<span class="p">[</span><span class="n">GCC</span> <span class="mf">4.9</span><span class="o">.</span><span class="mi">3</span><span class="p">]</span> <span class="n">on</span> <span class="n">linux</span>
<span class="n">Type</span> <span class="s2">"help"</span><span class="p">,</span> <span class="s2">"copyright"</span><span class="p">,</span> <span class="s2">"credits"</span> <span class="ow">or</span> <span class="s2">"license"</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">>>></span> <span class="kn">import</span> <span class="nn">pickle</span>
<span class="o">>>></span> <span class="kn">from</span> <span class="nn">bson.objectid</span> <span class="k">import</span> <span class="n">ObjectId</span>
<span class="o">>>></span> <span class="n">oid</span> <span class="o">=</span> <span class="n">ObjectId</span><span class="p">()</span>
<span class="o">>>></span> <span class="n">oid</span>
<span class="n">ObjectId</span><span class="p">(</span><span class="s1">'4f96f20c430ee6bd06000000'</span><span class="p">)</span>
<span class="o">>>></span> <span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="n">protocol</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">b</span><span class="s1">'</span><span class="se">\x80\x02</span><span class="s1">cbson.objectid</span><span class="se">\n</span><span class="s1">ObjectId</span><span class="se">\n</span><span class="s1">q</span><span class="se">\x00</span><span class="s1">)</span><span class="se">\x81</span><span class="s1">q</span><span class="se">\x01</span><span class="s1">c_codecs</span><span class="se">\n</span><span class="s1">encode\...'</span>
<span class="n">Python</span> <span class="mf">2.6</span><span class="o">.</span><span class="mi">9</span> <span class="p">(</span><span class="n">unknown</span><span class="p">,</span> <span class="n">Feb</span> <span class="mi">26</span> <span class="mi">2014</span><span class="p">,</span> <span class="mi">12</span><span class="p">:</span><span class="mi">39</span><span class="p">:</span><span class="mi">10</span><span class="p">)</span>
<span class="p">[</span><span class="n">GCC</span> <span class="mf">4.7</span><span class="o">.</span><span class="mi">3</span><span class="p">]</span> <span class="n">on</span> <span class="n">linux2</span>
<span class="n">Type</span> <span class="s2">"help"</span><span class="p">,</span> <span class="s2">"copyright"</span><span class="p">,</span> <span class="s2">"credits"</span> <span class="ow">or</span> <span class="s2">"license"</span> <span class="k">for</span> <span class="n">more</span> <span class="n">information</span><span class="o">.</span>
<span class="o">>>></span> <span class="kn">import</span> <span class="nn">pickle</span>
<span class="o">>>></span> <span class="n">pickle</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s1">'</span><span class="se">\x80\x02</span><span class="s1">cbson.objectid</span><span class="se">\n</span><span class="s1">ObjectId</span><span class="se">\n</span><span class="s1">q</span><span class="se">\x00</span><span class="s1">)</span><span class="se">\x81</span><span class="s1">q</span><span class="se">\x01</span><span class="s1">c_codecs</span><span class="se">\n</span><span class="s1">encode\...'</span><span class="p">)</span>
<span class="n">ObjectId</span><span class="p">(</span><span class="s1">'4f96f20c430ee6bd06000000'</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Python 3 FAQ</a><ul>
<li><a class="reference internal" href="#what-python-3-versions-are-supported">What Python 3 versions are supported?</a></li>
<li><a class="reference internal" href="#are-there-any-pymongo-behavior-changes-with-python-3">Are there any PyMongo behavior changes with Python 3?</a></li>
<li><a class="reference internal" href="#why-can-t-i-share-pickled-objectids-between-some-versions-of-python-2-and-3">Why can’t I share pickled ObjectIds between some versions of Python 2 and 3?</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="changelog.html"
title="previous chapter">Changelog</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="migrate-to-pymongo3.html"
title="next chapter">PyMongo 3 Migration Guide</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/python3.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="migrate-to-pymongo3.html" title="PyMongo 3 Migration Guide"
>next</a> |</li>
<li class="right" >
<a href="changelog.html" title="Changelog"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">PyMongo 3.4.0 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="changelog.html" >Changelog</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2017 - 2015, MongoDB, Inc..
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.9.
</div>
</body>
</html>
|