Open simonmorley opened 9 years ago
Actually, Mongoid.default_session has been depreciated too and need to be replaced with: default_client
Will test further.
I'm getting this error with Mongoid 5: https://travis-ci.org/diowa/ruby2-rails4-bootstrap-heroku/builds/81394387#L313
/home/travis/build/diowa/ruby2-rails4-bootstrap-heroku/vendor/bundle/ruby/2.2.0/gems/mongo-2.1.0/lib/mongo/server_selector.rb:68:in `fetch': key not found: "primary" (KeyError)
+1 I'm getting this error (just in case someone is googling it):
NoMethodError: undefined method `each_pair' for "primary":String
from [redacted]/gems/bson-3.2.4/lib/bson/document.rb:82:in `initialize'
caused by
database['system.namespaces'].find(:name => { '$not' => /\.system\.|\$/ }).to_a
Edit: it seems that it's not related. I'm investigating.
@fonji Would love to hear what you find. I keep running into that one too and my knowledge of MongoDB / Mongoid is not deep enough to investigate this issue.
@vindia: sorry, I'm in a hurry and didn't find the cause in the time I allowed myself to investigate. I tried a fork of MongoidCleaner that is supposed to support Mongoid 5 and I still got the same error. I rolled back to Mongoid 4 for the time being and will try again when I'll have more time (if that ever happens).
@fonji Thanks! I think I will stick to Mongo 2.6 and Mongoid 4.0 for the time being.
I have the same error of @fonji. anyone has a workaround for this issue?
hello guys, I was able to get rid of this error by updating my mongoid.yml:
test:
sessions:
default:
database: my_app_test
hosts:
- localhost:27017
options:
- read: primary
+ read:
+ mode: :primary
# In the test environment we lower the retries and retry interval to
# low amounts for fast failures.
max_retries: 1
Please let me know if this works for you :)
thanks @sbounmy, I tried but still having the same issue. What happens with the "clients:" and "database:" keys??
ups, i've updated my last post. For full mongoid.yml reference: https://github.com/mongodb/mongoid/blob/master/lib/rails/generators/mongoid/config/templates/mongoid.yml
Are you sure you have correctly updated your mongoid.yml?
Great! now with that configuratin is working. Thanks!
That works, thanks! BTW, you can also leave the who read
option out, as :primary
is the default anyway.
I would also love to see Mongoid 5 compatibility :+1:
I'm not a MongoidCleaner user but I ran into the same issue when upgrading to Mongoid 5. Changing the mongoid.yml config file worked for me:
options:
read:
mode: :primary
max_pool_size: 1
@sbounmy thank you, it works for me!
@sbounmy thank you for the hint!
+1 for mongoid 5.0 dependency update
@snow @alexkravets :beers:
Make "primary" a symbol ":primary" worked for me too.
it doesn't work for me. In my environment, the versions are
version 1.5.1 works for me
sample repos:
umm, although I upgraded these gems to the same version, but it doesn't work yet...
In my case, collections
returns an empty array. collections
uses system.namespace
but the manual says it is deprecated since version mongodb versions 3.0. so it should not work, I think.
I'm a beginner for MongoDB. Hoping anybody helps me :)
I've resolved my problem! The problem is caused by using WiredTiger storage engine, default storage engine since 3.2. After I changed my mongo's configuration as follows, database_cleaner works.
storage:
dbPath: /usr/local/var/mongoedb
engine: mmpav1 # <= Added
So this means that database_cleaner doesn't work with wiredTiger, in other words v3.2 or newer of mongodb in default.
@satoryu thanks for sharing this
I'm using MongoDB v3.2.4 with mongoid-5.1.1, and database_cleaner-1.5.1. The cleaning doesn't seem to be working anymore. I'm not sure if it's due to the engine, so far I'm using the default. I tried to use mmapv1
per https://docs.mongodb.org/manual/reference/configuration-options/ but my MongoDB won't restart. Anyone else having problems?
Here's my spec_helper.rb
config.before(:suite) do
# DatabaseCleaner.strategy = :truncation
DatabaseCleaner[:mongoid].strategy = :truncation
DatabaseCleaner.clean_with(:truncation)
Capybara.javascript_driver = :webkit
end
config.before(:each) do
Rails.cache.clear
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
Capybara.reset_sessions!
end
The pull request from DatabaseCleaner/database_cleaner#343 fixes compatibility with Mongo 3 but doesn't address the problem of Mongo 3 + Mongoid 5.
In the current master, the Mongo 2 truncation mixin contains this:
And this commit won't work with mongo v3. Instead, I've found this to work:
Plus, you also need the sessions function, also excluded:
But that won't work with Mongo 2 I don't believe.
What is the plan for Mongo3 - do you want me to merge this in to a separate module or have you already dealt with?
It seems this has been covered but not for Mongoid 5.
https://github.com/DatabaseCleaner/database_cleaner/pull/343 https://github.com/DatabaseCleaner/database_cleaner/pull/349 https://github.com/andreale/database_cleaner/commit/e9b2c8cd5d335006b8a59e2a89cdbd3fb9e5a23d https://github.com/DatabaseCleaner/database_cleaner/issues/386