我的问题更清楚:我使用的是mongodb,集合中的每个文档都是:
{
u'cell_latlng': {
u'type': u'Polygon',
u'coordinates': [
[
[
...
],
[
...
],
[
...
],
[
...
]
]
]
},
u'self': {
u'Bus Line': 1,
u'Meeting Room': 1,
u'Neighborhood': 1,
u'Home (private)': 1,
u'Food': 1,
u'High School': 2,
u'Elementary School': 1,
u'Beach': 1,
u'Other Repair Shop': 1
},
u'_id': ObjectId('5545bed4e139c7dcde660f5a'),
u'point_latlng': {
u'type': u'Point',
u'coordinates': [
...
]
},
u'area': 100
}
现在我需要在集合中找到一个特定的文档(该集合称为citymap)。我知道字段'self'的值,这个值叫做feature [0],所以我只使用:
results = citymap.find({'self':feature[0]})
然而,
results.count() == 0
我再次检查功能[0],我确信它是:
feature[0] = {u'Bus Line': 1, u'Meeting Room': 1, u'Neighborhood': 1, u'Home (private)': 1, u'Food': 1, u'High School': 2, u'Elementary School': 1, u'Beach': 1, u'Other Repair Shop': 1}
这与doc中的完全相同,为什么我不能用这句话找到这个doc?
非常感谢任何帮助
答案 0 :(得分:0)
让我们检查一下这个脚本。假设你的java.lang.RuntimeException: java.lang.NullPointerException
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:178)
at com.intellij.idea.MainImpl$1$1$1.run(MainImpl.java:52)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:312)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:738)
at java.awt.EventQueue.access$300(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:699)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:708)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:362)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Caused by: java.lang.NullPointerException
at com.android.tools.idea.welcome.AndroidVirtualDevice.<init>(AndroidVirtualDevice.java:81)
at com.android.tools.idea.welcome.InstallComponentsPath.createComponentTree(InstallComponentsPath.java:89)
at com.android.tools.idea.welcome.InstallComponentsPath.init(InstallComponentsPath.java:215)
at com.android.tools.idea.wizard.DynamicWizardPath.attachToWizard(DynamicWizardPath.java:97)
at com.android.tools.idea.wizard.DynamicWizard.addPath(DynamicWizard.java:233)
at com.android.tools.idea.welcome.FirstRunWizard.init(FirstRunWizard.java:75)
at com.android.tools.idea.welcome.FirstRunWizardHost.setupWizard(FirstRunWizardHost.java:100)
at com.android.tools.idea.welcome.FirstRunWizardHost.getWelcomePanel(FirstRunWizardHost.java:92)
at com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame.<init>(WelcomeFrame.java:68)
at com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame.showNow(WelcomeFrame.java:173)
at com.intellij.idea.IdeaApplication$IdeStarter.main(IdeaApplication.java:302)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:172)
... 16 more
对象是这样的
feature
迭代var feature = {u'Bus Line': 1, u'Meeting Room': 1, u'Neighborhood': 1, u'Home (private)': 1, u'Food': 1, u'High School': 2, u'Elementary School': 1, u'Beach': 1, u'Other Repair Shop': 1}
个对象并将每个键附加为feature
并将它们推入新对象。检查以下功能:
self
现在,如果您键入var appendSelf = {};
function appendData(data) {
for (var k in data) {
if (data.hasOwnProperty(k)) {
appendSelf["self.".concat(k)] = data[k]; //append self to every keys and set it's respective values
}
}
}
,则在控制台上将此函数调用为appendData(feature)
,然后它会显示附加appendSelf
的对象
self
因此,在查找条件中使用此> appendSelf
{
"self.u'Bus Line": 1,
"self.u'Meeting Room": 1,
"self.u'Neighborhood": 1,
"self.u'Home (private)": 1,
"self.u'Food": 1,
"self.u'High School": 4,
"self.u'Elementary School": 1,
"self.u'Beach": 1,
"self.u'Other Repair Shop": 1
}
作为显示预期结果的appendSelf
。