<p>根据<a href="https://github.com/mongodb/mongo-python-driver/blob/master/pymongo/collection.py">source</a>,可以将<code>check_keys</code>设置为False:</p>
<pre><code> test.insert(d,check_keys=False)
def insert(self, doc_or_docs, manipulate=True,
safe=None, check_keys=True, continue_on_error=False, **kwargs):
</code></pre>
<p>它确实有效:</p>
<pre><code>In [28]: d = {'.aaa' : '.bbb'}
In [29]: test.insert(d,check_keys=False)
Out[29]: ObjectId('54ea604bf9664e211e8ed4e6')
</code></pre>
<p>docstring声明:</p>
<blockquote>
<ul>
<li><code>check_keys</code> (optional): If <code>True</code> check if keys start with '$'
or contain '.', raising :class:<code>~pymongo.errors.InvalidName</code> in either case.</li>
</ul>
</blockquote>
<p>您似乎可以使用除两个<code>$</code>或<code>.</code>之外的任何字符,因此前导下划线或任何其他字符都很好,可能是更好的选择。</p>
<p>常见问题解答中有关于<a href="http://docs.mongodb.org/manual/faq/developers/#faq-dollar-sign-escaping">escaping </a>的信息:</p>
<blockquote>
<p>In some cases, you may wish to build a BSON object with a user-provided key. In these situations, keys will need to substitute the reserved $ and . characters. Any character is sufficient, but consider using the Unicode full width equivalents: U+FF04 (i.e. “$”) and U+FF0E (i.e. “.”).</p>
</blockquote>
<p>点符号faq解释了为什么使用<code>.</code>不是一个好主意:</p>
<blockquote>
<p>MongoDB uses the dot notation to access the elements of an array and to access the fields of an embedded document.
To access an element of an array by the zero-based index position, concatenate the array name with the dot (.) and zero-based index position, and enclose in quotes:</p>
</blockquote>