为什么mongodb motor不能正确解析数据?

为什么mongodb motor不能正确解析数据?,mongodb,tornado,tornado-motor,Mongodb,Tornado,Tornado Motor,我有一个巨大的tornado应用程序,它是以阻塞方式编写的。我正在尝试将我的db调用转换为运行异步。我有很多问题 我将mongo调用保存在名为lib的顶级文件夹中,并将所有视图保存在app文件夹中 我犯的错误 Traceback (most recent call last): File "/Users/marcsantiago/staging_env/lib/python2.7/site-packages/tornado/web.py", line 1445, in _execute

我有一个巨大的tornado应用程序,它是以阻塞方式编写的。我正在尝试将我的db调用转换为运行异步。我有很多问题

我将mongo调用保存在名为lib的顶级文件夹中,并将所有视图保存在app文件夹中

我犯的错误

Traceback (most recent call last):
  File "/Users/marcsantiago/staging_env/lib/python2.7/site-packages/tornado/web.py", line 1445, in _execute
    result = yield result
  File "/Users/marcsantiago/staging_env/lib/python2.7/site-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/Users/marcsantiago/staging_env/lib/python2.7/site-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "/Users/marcsantiago/staging_env/lib/python2.7/site-packages/tornado/gen.py", line 1017, in run
    yielded = self.gen.send(value)
  File "/Users/marcsantiago/pubgears/app/admin.py", line 179, in get
    notes, start_date, stats, last_updated = self.db_data()
  File "/Users/marcsantiago/pubgears/app/admin.py", line 76, in db_data
    while (yield chain_slugs_updated.fetch_next):
AttributeError: 'NoneType' object has no attribute 'fetch_next'
所以在lib文件夹中我有这个方法

def get_chains_updated(date):
  slugs = []
  # Chain class can't do aggregate could create a class instance if i want
  cursor = db.chain.aggregate([
    {'$match':{'last_update':{'$gt':date}}}, 
    {'$group':{'_id':{'site':'$site'}, 'total':{'$sum':'$count'}}}
  ])

  while (yield cursor.fetch_next):
    res = yield cursor.next_object()
    slugs.append(res['_id']['site'])

  yield slugs
后来我把这种方法称为我的观点之一

chain_slugs_updated = yield chaindb.get_chains_updated(yesterday)
slugs = []
#for site in chain_slugs_updated:
while (yield chain_slugs_updated.fetch_next):
  site = chain_slugs_updated.next_object()
  slugs.append('<a href="/admin/sites/settings?slug=%s">%s</a>' % (site, site))
notes.append('<strong>%s</strong> chains have been updated in the past 24 hours (%s).' % (chain_slugs_updated.count(), ', '.join(slugs)))
看法

chain\u slugs\u updated=chaindb.get\u chains\u updated(昨天)
鼻涕虫=[]
对于链中的站点\u段塞\u更新:
slug.append(“”%(站点,站点))
注意。追加(“%s链在过去24小时内已更新(%s)。”%(len(链段塞更新),“,”。加入(段塞)))

我有大量的代码需要翻译才能使这个异步正确工作,我非常感谢任何帮助。谢谢。

要从
get\u-updated
返回对象列表,您必须
返回slug
列表(Python 3)或
raise gen.return(slug)
(所有Python版本)。有关详细信息,请参阅

def get_chains_updated(date):
  slugs = []
  # Chain class can't do aggregate could create a class instance if i want
  results = db.chain.aggregate([
    {'$match':{'last_update':{'$gt':date}}}, 
    {'$group':{'_id':{'site':'$site'}, 'total':{'$sum':'$count'}}}
  ])
  for res in results:
    slugs.append(res['_id']['site'])
  return slugs
chain_slugs_updated = chaindb.get_chains_updated(yesterday)
    slugs = []
    for site in chain_slugs_updated:
      slugs.append('<a href="/admin/sites/settings?slug=%s">%s</a>' % (site, site))
    notes.append('<strong>%s</strong> chains have been updated in the past 24 hours (%s).' % (len(chain_slugs_updated), ', '.join(slugs)))