【发布时间】:2012-07-28 14:52:58
【问题描述】:
这是我关于洪流索引器的另一个 MongoDB 问题的后续。
我正在制作一个开源 torrent 索引器(本质上就像一个迷你 TPB),目前为后端提供 SQLite 和 MongoDB。
但是,我在其中的 MongoDB 部分遇到了问题。在 Sinatra 中,我在尝试上传种子或搜索种子时收到 。
在上传时,需要标记 torrent — 在这里失败了。添加标签的代码如下:
def add_tag(tag)
if $sqlite
unless tag_exists? tag
$db.execute("insert into #{$tag_table} values ( ? )", tag)
end
id = $db.execute("select oid from #{$tag_table} where tag = ?", tag)
return id[0]
elsif $mongo
unless tag_exists? tag
$tag.insert({:tag => tag})
end
return $tag.find({:tag => tag})[:_id] #this is the line it presumably crashes on
end
end
它到达第 105 行(如上所述),然后失败。这是怎么回事?此外,作为仅供参考,随着解决方案的出现,这可能会变成其他一些问题。
谢谢!
编辑
因此,我没有使用[:_id] 返回标签结果,而是将 elsif 中的块更改为:
id = $tag.find({:tag => tag})
puts id.inspect
return id
仍然出现错误。您可以在http://torrent.hypeno.de 看到演示,在http://github.com/tekknolagi/indexer/ 看到源代码
【问题讨论】:
标签: ruby mongodb sinatra typeerror