我在配置新的MacBookPro以运行Rails 3.2应用程序时遇到了问题。
虽然我知道代码有效,但因为它适用于我的同事
mongoexport
mongorestore
从错误中看,mongo似乎试图在每个请求上重新创建集合......但我知道我已经恢复了导出的集合。 这是错误:
Mongo::OperationFailure: Database command 'create' failed: (ok: '0.0'; errmsg: 'collection already exists'; code: '48').
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongo-1.6.2/lib/mongo/db.rb:526:in `command'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongo-1.6.2/lib/mongo/db.rb:297:in `create_collection'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-2.4.12/lib/mongoid/collections/master.rb:41:in `initialize'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-2.4.12/lib/mongoid/collection.rb:127:in `new'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-2.4.12/lib/mongoid/collection.rb:127:in `master'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-2.4.12/lib/mongoid/collection.rb:42:in `find'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-2.4.12/lib/mongoid/contexts/mongo.rb:93:in `count'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-2.4.12/lib/mongoid/criteria.rb:45:in `count'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/mongoid-2.4.12/lib/mongoid/finders.rb:39:in `count'
from (irb):1
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /usr/local/var/rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
我们尝试仅恢复集合的子集,并尝试运行较新版本的MongoDB服务器。没有运气,但是。 我们很难过。任何帮助或建议都会受到欢迎。
答案 0 :(得分:1)
无法弄清楚为什么会抛出此错误
它说得很清楚errmsg: 'collection already exists'
所以,如果集合已经存在,你是否检查了数据库?另外,您是否在每次应用程序启动时检查您的代码是否尝试创建集合?
您可以连接到数据库并执行
db.getCollectionNames()
这将显示至少插入一个文档的集合,即使它们当前是空的。
如果您想删除它们以运行您的应用,您可以
db.myColl.drop()