/usr/share/doc/python-pymongo-doc/html/api/bson/objectid.html is in python-pymongo-doc 2.6.3-1build1.
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 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | <!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>objectid – Tools for working with MongoDB ObjectIds — PyMongo 2.6.3 documentation</title>
<link rel="stylesheet" href="../../_static/default.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
VERSION: '2.6.3',
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="top" title="PyMongo 2.6.3 documentation" href="../../index.html" />
<link rel="up" title="bson – BSON (Binary JSON) Encoding and Decoding" href="index.html" />
<link rel="next" title="son – Tools for working with SON, an ordered mapping" href="son.html" />
<link rel="prev" title="min_key – Representation for the MongoDB internal MinKey type" href="min_key.html" />
</head>
<body>
<div class="related">
<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="son.html" title="son – Tools for working with SON, an ordered mapping"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="min_key.html" title="min_key – Representation for the MongoDB internal MinKey type"
accesskey="P">previous</a> |</li>
<li><a href="../../index.html">PyMongo 2.6.3 documentation</a> »</li>
<li><a href="../index.html" >API Documentation</a> »</li>
<li><a href="index.html" accesskey="U"><tt class="docutils literal"><span class="pre">bson</span></tt> – BSON (Binary JSON) Encoding and Decoding</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="module-bson.objectid">
<span id="objectid-tools-for-working-with-mongodb-objectids"></span><h1><tt class="xref py py-mod docutils literal"><span class="pre">objectid</span></tt> – Tools for working with MongoDB ObjectIds<a class="headerlink" href="#module-bson.objectid" title="Permalink to this headline">¶</a></h1>
<p>Tools for working with MongoDB <a class="reference external" href="http://dochub.mongodb.org/core/objectids">ObjectIds</a>.</p>
<dl class="class">
<dt id="bson.objectid.ObjectId">
<em class="property">class </em><tt class="descclassname">bson.objectid.</tt><tt class="descname">ObjectId</tt><big>(</big><span class="optional">[</span><em>oid=None</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#bson.objectid.ObjectId" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize a new ObjectId.</p>
<p>If <cite>oid</cite> is <tt class="docutils literal"><span class="pre">None</span></tt>, create a new (unique) ObjectId. If <cite>oid</cite>
is an instance of (<tt class="xref py py-class docutils literal"><span class="pre">basestring</span></tt> (<tt class="xref py py-class docutils literal"><span class="pre">str</span></tt> or <tt class="xref py py-class docutils literal"><span class="pre">bytes</span></tt>
in python 3), <a class="reference internal" href="#bson.objectid.ObjectId" title="bson.objectid.ObjectId"><tt class="xref py py-class docutils literal"><span class="pre">ObjectId</span></tt></a>) validate it and use that. Otherwise,
a <tt class="xref py py-class docutils literal"><span class="pre">TypeError</span></tt> is raised. If <cite>oid</cite> is invalid,
<a class="reference internal" href="errors.html#bson.errors.InvalidId" title="bson.errors.InvalidId"><tt class="xref py py-class docutils literal"><span class="pre">InvalidId</span></tt></a> is raised.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>oid</cite> (optional): a valid ObjectId (12 byte binary or 24 character
hex string)</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.1: </span>The <cite>oid</cite> parameter can be a <tt class="docutils literal"><span class="pre">unicode</span></tt> instance (that contains
only hexadecimal digits).</p>
</div>
<div class="admonition-see-general-mongodb-documentation admonition seealso">
<p class="first admonition-title">See also</p>
<p class="admonition-title">See general MongoDB documentation</p>
<p class="last"><a class="reference external" href="http://dochub.mongodb.org/core/objectids" name="bson.objectid.ObjectId"><em>objectids</em></a></p>
</div>
<dl class="describe">
<dt>
<tt class="descname">str(o)</tt></dt>
<dd><p>Get a hex encoded version of <a class="reference internal" href="#bson.objectid.ObjectId" title="bson.objectid.ObjectId"><tt class="xref py py-class docutils literal"><span class="pre">ObjectId</span></tt></a> <cite>o</cite>.</p>
<p>The following property always holds:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">o</span> <span class="o">=</span> <span class="n">ObjectId</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">o</span> <span class="o">==</span> <span class="n">ObjectId</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">o</span><span class="p">))</span>
<span class="go">True</span>
</pre></div>
</div>
<p>This representation is useful for urls or other places where
<tt class="docutils literal"><span class="pre">o.binary</span></tt> is inappropriate.</p>
</dd></dl>
<dl class="attribute">
<dt id="bson.objectid.ObjectId.binary">
<tt class="descname">binary</tt><a class="headerlink" href="#bson.objectid.ObjectId.binary" title="Permalink to this definition">¶</a></dt>
<dd><p>12-byte binary representation of this ObjectId.</p>
</dd></dl>
<dl class="classmethod">
<dt id="bson.objectid.ObjectId.from_datetime">
<em class="property">classmethod </em><tt class="descname">from_datetime</tt><big>(</big><em>generation_time</em><big>)</big><a class="headerlink" href="#bson.objectid.ObjectId.from_datetime" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a dummy ObjectId instance with a specific generation time.</p>
<p>This method is useful for doing range queries on a field
containing <a class="reference internal" href="#bson.objectid.ObjectId" title="bson.objectid.ObjectId"><tt class="xref py py-class docutils literal"><span class="pre">ObjectId</span></tt></a> instances.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">It is not safe to insert a document containing an ObjectId
generated using this method. This method deliberately
eliminates the uniqueness guarantee that ObjectIds
generally provide. ObjectIds generated with this method
should be used exclusively in queries.</p>
</div>
<p><cite>generation_time</cite> will be converted to UTC. Naive datetime
instances will be treated as though they already contain UTC.</p>
<p>An example using this helper to get documents where <tt class="docutils literal"><span class="pre">"_id"</span></tt>
was generated before January 1, 2010 would be:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">gen_time</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="p">(</span><span class="mi">2010</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">dummy_id</span> <span class="o">=</span> <span class="n">ObjectId</span><span class="o">.</span><span class="n">from_datetime</span><span class="p">(</span><span class="n">gen_time</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">collection</span><span class="o">.</span><span class="n">find</span><span class="p">({</span><span class="s">"_id"</span><span class="p">:</span> <span class="p">{</span><span class="s">"$lt"</span><span class="p">:</span> <span class="n">dummy_id</span><span class="p">}})</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>generation_time</cite>: <tt class="xref py py-class docutils literal"><span class="pre">datetime</span></tt> to be used
as the generation time for the resulting ObjectId.</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>Properly handle timezone aware values for
<cite>generation_time</cite>.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.6.</span></p>
</div>
</dd></dl>
<dl class="attribute">
<dt id="bson.objectid.ObjectId.generation_time">
<tt class="descname">generation_time</tt><a class="headerlink" href="#bson.objectid.ObjectId.generation_time" title="Permalink to this definition">¶</a></dt>
<dd><p>A <tt class="xref py py-class docutils literal"><span class="pre">datetime.datetime</span></tt> instance representing the time of
generation for this <a class="reference internal" href="#bson.objectid.ObjectId" title="bson.objectid.ObjectId"><tt class="xref py py-class docutils literal"><span class="pre">ObjectId</span></tt></a>.</p>
<p>The <tt class="xref py py-class docutils literal"><span class="pre">datetime.datetime</span></tt> is timezone aware, and
represents the generation time in UTC. It is precise to the
second.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 1.8: </span>Now return an aware datetime instead of a naive one.</p>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.</span></p>
</div>
</dd></dl>
<dl class="classmethod">
<dt id="bson.objectid.ObjectId.is_valid">
<em class="property">classmethod </em><tt class="descname">is_valid</tt><big>(</big><em>oid</em><big>)</big><a class="headerlink" href="#bson.objectid.ObjectId.is_valid" title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if a <cite>oid</cite> string is valid or not.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><cite>oid</cite>: the object id to validate</li>
</ul>
</td>
</tr>
</tbody>
</table>
<div class="versionadded">
<p><span class="versionmodified">New in version 2.3.</span></p>
</div>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="min_key.html"
title="previous chapter"><tt class="docutils literal"><span class="pre">min_key</span></tt> – Representation for the MongoDB internal MinKey type</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="son.html"
title="next chapter"><tt class="docutils literal"><span class="pre">son</span></tt> – Tools for working with SON, an ordered mapping</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../../_sources/api/bson/objectid.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<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="son.html" title="son – Tools for working with SON, an ordered mapping"
>next</a> |</li>
<li class="right" >
<a href="min_key.html" title="min_key – Representation for the MongoDB internal MinKey type"
>previous</a> |</li>
<li><a href="../../index.html">PyMongo 2.6.3 documentation</a> »</li>
<li><a href="../index.html" >API Documentation</a> »</li>
<li><a href="index.html" ><tt class="docutils literal"><span class="pre">bson</span></tt> – BSON (Binary JSON) Encoding and Decoding</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2008 - 2012, 10gen, Inc..
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.
</div>
</body>
</html>
|