回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我使用的是mongodb3.2.1/python3.4/pymongo/pandas 0.17(尽管后两个可能完全不涉及这个问题)。在</p>
<p>我对MongoDB find有一个非常奇怪(错误)的行为。在</p>
<p>我有一个收藏,里面有这样一个文件:</p>
<pre><code> {
"_id" : NumberLong(-1819413477243867792),
"targetentity" : "NODOGENERICO .ag.HP_BAR_DEG_APP_1",
"tx" : false,
"ocname" : ".oc.serv6",
"specificproblem" : null,
"saf" : false,
"iscriticalnode" : null,
"checkmask" : null,
"notificationidentifier" : 1347592,
"province" : null,
"usertext" : null,
"additionaltext" : "AAA Invalid Response",
"director" : ".temip.madrids01_director",
"problemoccurences" : 1,
"usertags" : null,
"managedobject" : "NODOGENERICO .ag.HP_BAR_DEG_APP_1",
"isacceptednode" : null,
"elementcode" : null,
"state" : "Terminated",
"probablecause" : "Unknown",
"ran" : false,
"counttotal" : 1,
"locationcode" : "NULL",
"problemstatus" : "Closed",
"structurednotes" : null,
"collection" : "serv6",
"operatornotes" : null,
"alarmtype" : "CommunicationsAlarm",
"workinfo" : null,
"perceivedseverity" : "Major",
"core" : true,
"eventtime" : NumberLong(1467342666000),
"originalseverity" : "Major",
"vendor" : "Several",
"controlelementcode" : null,
"outageflag" : false,
"incident" : null,
}
</code></pre>
<p>这个“_id”基本上是一个使用python3.4的“Hash”内置方法计算的散列。在</p>
<p>问题是,在插入这个id之后,我找不到任何具有此id的元素。在</p>
<p>我试过了(现在我直接在mongo终端上尝试这个,但是在Pymongo上它得到了相同的结果):</p>
<blockquote>
<p>db.getCollection('unique_alarm').find({"_id": NumberLong(-1819413477243867792)}</p>
</blockquote>
<p>以及</p>
<blockquote>
<p>db.getCollection('unique_alarm').find({"_id": -1819413477243867792})</p>
</blockquote>
<p>对于这两个我都明白了:</p>
<blockquote>
<p>Fetched 0 record(s) in 1ms</p>
</blockquote>
<p>我以为问题在于我如何处理NumberLong,但是对于field eventtime(具有相同类型)我完全没有问题。在</p>
<p>例如,对于事件时间,如果我询问:</p>
<blockquote>
<p>db.getCollection('unique_alarm').find({"eventtime" :
NumberLong(1467342666000)})</p>
</blockquote>
<p>或通过:</p>
<blockquote>
<p>db.getCollection('unique_alarm').find({"eventtime" :1467342666000})</p>
</blockquote>
<p>这两个查询都会再次返回第一个文档,没有问题。在</p>
<p>有什么线索吗?为什么前两个查询返回0个结果?</strong></p>
<p>关于我的试错的更多信息:</p>
<ul>
<li>不管字段是“\u id”还是其他字段,我都无法搜索这些数字</li>
<li>我用pymongo插入这些文档</li>
<li>如果我再次尝试插入此文档(使用pymongo或mongodb终端),就会出现重复密钥的错误。。。在</li>
</ul>