Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intgeration with official Mongo driver 2.0.0. #3941

Merged
merged 27 commits into from
May 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d2a6507
First pass integration of Mongo Ruby driver 2
durran Jan 22, 2015
4aa2ccb
Udpating tests to use auth
durran Feb 9, 2015
8c3123b
Get specs running with authentication, passing on 2.6 and 3.0
durran Feb 9, 2015
100e94c
Update to have travis matrix run on multiple mongodb versions
durran Feb 10, 2015
f102a87
Run appropriate specs depending on version
durran Feb 17, 2015
4dc58fc
Remove text search context since it's now a query
durran Feb 17, 2015
af41579
Fix 2.6 related role issues
durran Feb 18, 2015
2bbba35
Point at rc, fix index and delete syntax changes
durran Mar 21, 2015
1e8aa58
Bump to 2.0
durran Mar 30, 2015
0e796c0
Fixing query cache and query expectations
durran May 19, 2015
6eb74b4
Back to standard tests with no auth
durran May 19, 2015
19f15d1
Fix uri handling with db name
durran May 20, 2015
de07e9e
Unpend eager loading specs
durran May 20, 2015
fc6c806
Remove find and modify contexts - provided no extra value
durran May 20, 2015
11b5e19
Removing text search related specs
durran May 20, 2015
fdfbdb6
Implement find and modify related operations
durran May 20, 2015
dd5e570
Rename query in mongo context to view
durran May 20, 2015
155aa6c
Remove the no timeout specs
durran May 25, 2015
5248751
Revert "Back to standard tests with no auth"
durran May 25, 2015
0068b26
Fixing auth on 3.0.0
durran May 25, 2015
33722a1
Make direct session setting private
durran May 25, 2015
68b82f0
Bit errors on 2.4 for null fields
durran May 26, 2015
00e0be0
Fixing atomic operations failures
durran May 26, 2015
bc718d4
Need 2.1 driver for session closing
durran May 26, 2015
37fd26d
Fix rebase failures
durran May 26, 2015
2d19d8d
Use latest mongo versions
durran May 26, 2015
c87b1b1
Updating changelog
durran May 26, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
language: ruby

services: mongodb

bundler_args: --without development

rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2
- 2.1.5
- 2.2.0
- jruby

gemfile:
- Gemfile
- gemfiles/rails41.gemfile
- gemfiles/rails42.gemfile

env: JRUBY_OPTS="--server -J-Xms512m -J-Xmx1024m"
env:
global:
- CI="travis"
- JRUBY_OPTS="--server -J-Xms512m -J-Xmx1024m"
matrix:
- MONGODB=2.4.14
- MONGODB=2.6.10
- MONGODB=3.0.3

sudo: false
before_script:
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-${MONGODB}.tgz -O /tmp/mongodb.tgz
- tar -xvf /tmp/mongodb.tgz
- mkdir /tmp/data
- ${PWD}/mongodb-linux-x86_64-${MONGODB}/bin/mongod --dbpath /tmp/data --bind_ip 127.0.0.1 --auth &> /dev/null &

notifications:
email: false
Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
For instructions on upgrading to newer versions, visit
[mongoid.org](http://mongoid.org/en/mongoid/docs/upgrading.html).

## 4.0.3 - Not released
## 5.0.0 - Not released

### Major Changes (Backwards Incompatible)

* Mongoid now uses the official Mongo Ruby Driver 2.x instead of Moped.

* Most driver specific configuration options have changed, please see [here](http://docs.mongodb.org/ecosystem/tutorial/ruby-driver-tutorial/#ruby-options) for the new options.

* `find_and_modify` has been removed and replaced with 3 options: `find_one_and_update`, `find_one_and_delete` and `find_one_and_replace`.

* `text_search` has been removed as it is now a `$text` option in a query from 2.6 on.

* Mongoid no longer supports MongoDB 2.2 - support is now for only 2.4 and higher.

### New Features

Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source "https://rubygems.org"

gemspec

gem "rake"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails41.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source "https://rubygems.org"
gemspec path: '..'

gem "mongo", :github => "mongodb/mongo-ruby-driver"
gem "rake"
gem "actionpack", "~> 4.1.8"
gem "activemodel", "~> 4.1.8"
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails42.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
source "https://rubygems.org"
gemspec path: '..'

gem "mongo", :github => "mongodb/mongo-ruby-driver"
gem "rake"
gem "actionpack", "~> 4.2.0"
gem "activemodel", "~> 4.2.0"
Expand Down
3 changes: 1 addition & 2 deletions lib/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
require "active_model"

require "origin"
require "moped"
require "mongo"

require "mongoid/version"
require "mongoid/config"
require "mongoid/loggable"
require "mongoid/sessions"
require "mongoid/document"
require "mongoid/log_subscriber"
require "mongoid/tasks/database"
require "mongoid/query_cache"

Expand Down
34 changes: 14 additions & 20 deletions lib/mongoid/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def configured?
# @param [ String ] name The database name.
#
# @since 3.0.0
def connect_to(name, options = { read: :primary })
def connect_to(name, options = { read: { mode: :primary }})
self.sessions = {
default: {
database: name,
Expand Down Expand Up @@ -169,7 +169,7 @@ def override_session(name)
#
# @since 2.0.2
def purge!
Sessions.default.collections.each(&:drop) and true
Sessions.default.database.collections.each(&:drop) and true
end

# Truncate all data in all collections, but not the indexes.
Expand All @@ -183,8 +183,8 @@ def purge!
#
# @since 2.0.2
def truncate!
Sessions.default.collections.each do |collection|
collection.find.remove_all
Sessions.default.database.collections.each do |collection|
collection.find.delete_many
end and true
end

Expand Down Expand Up @@ -217,22 +217,6 @@ def sessions
@sessions ||= {}
end

# Set the session configuration options.
#
# @example Set the session configuration options.
# config.sessions = { default: { hosts: [ "localhost:27017" ] }}
#
# @param [ Hash ] sessions The configuration options.
#
# @since 3.0.0
def sessions=(sessions)
raise Errors::NoSessionsConfig.new unless sessions
sess = sessions.with_indifferent_access
Validators::Session.validate(sess)
@sessions = sess
sess
end

# Get the time zone to use.
#
# @example Get the time zone.
Expand All @@ -256,5 +240,15 @@ def time_zone
def running_with_passenger?
@running_with_passenger ||= defined?(PhusionPassenger)
end

private

def sessions=(sessions)
raise Errors::NoSessionsConfig.new unless sessions
sess = sessions.with_indifferent_access
Validators::Session.validate(sess)
@sessions = sess
sess
end
end
end
2 changes: 1 addition & 1 deletion lib/mongoid/contextual/aggregable/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module Mongo
#
# @since 3.0.0
def aggregates(field)
result = collection.aggregate(pipeline(field)).to_a
result = collection.find.aggregate(pipeline(field)).to_a
if result.empty?
{ "count" => 0, "sum" => nil, "avg" => nil, "min" => nil, "max" => nil }
else
Expand Down
22 changes: 11 additions & 11 deletions lib/mongoid/contextual/atomic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module Atomic
#
# @since 3.0.0
def add_to_set(adds)
query.update_all("$addToSet" => collect_operations(adds))
view.update_many("$addToSet" => collect_operations(adds))
end

# Perform an atomic $bit operation on the matching documents.
Expand All @@ -28,7 +28,7 @@ def add_to_set(adds)
#
# @since 3.0.0
def bit(bits)
query.update_all("$bit" => collect_operations(bits))
view.update_many("$bit" => collect_operations(bits))
end

# Perform an atomic $inc operation on the matching documents.
Expand All @@ -42,7 +42,7 @@ def bit(bits)
#
# @since 3.0.0
def inc(incs)
query.update_all("$inc" => collect_operations(incs))
view.update_many("$inc" => collect_operations(incs))
end

# Perform an atomic $pop operation on the matching documents.
Expand All @@ -59,7 +59,7 @@ def inc(incs)
#
# @since 3.0.0
def pop(pops)
query.update_all("$pop" => collect_operations(pops))
view.update_many("$pop" => collect_operations(pops))
end

# Perform an atomic $pull operation on the matching documents.
Expand All @@ -75,7 +75,7 @@ def pop(pops)
#
# @since 3.0.0
def pull(pulls)
query.update_all("$pull" => collect_operations(pulls))
view.update_many("$pull" => collect_operations(pulls))
end

# Perform an atomic $pullAll operation on the matching documents.
Expand All @@ -89,7 +89,7 @@ def pull(pulls)
#
# @since 3.0.0
def pull_all(pulls)
query.update_all("$pullAll" => collect_operations(pulls))
view.update_many("$pullAll" => collect_operations(pulls))
end

# Perform an atomic $push operation on the matching documents.
Expand All @@ -103,7 +103,7 @@ def pull_all(pulls)
#
# @since 3.0.0
def push(pushes)
query.update_all("$push" => collect_operations(pushes))
view.update_many("$push" => collect_operations(pushes))
end

# Perform an atomic $pushAll operation on the matching documents.
Expand All @@ -117,7 +117,7 @@ def push(pushes)
#
# @since 3.0.0
def push_all(pushes)
query.update_all("$pushAll" => collect_operations(pushes))
view.update_many("$pushAll" => collect_operations(pushes))
end

# Perform an atomic $rename of fields on the matching documents.
Expand All @@ -135,7 +135,7 @@ def rename(renames)
ops[old_name] = new_name.to_s
ops
end
query.update_all("$rename" => collect_operations(operations))
view.update_many("$rename" => collect_operations(operations))
end

# Perform an atomic $set of fields on the matching documents.
Expand All @@ -149,7 +149,7 @@ def rename(renames)
#
# @since 3.0.0
def set(sets)
query.update_all("$set" => collect_operations(sets))
view.update_many("$set" => collect_operations(sets))
end

# Perform an atomic $unset of a field on the matching documents.
Expand All @@ -164,7 +164,7 @@ def set(sets)
# @since 3.0.0
def unset(*args)
fields = args.__find_args__.collect { |f| [database_field_name(f), true] }
query.update_all("$unset" => Hash[fields])
view.update_many("$unset" => Hash[fields])
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/contextual/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def command
#
# @since 3.0.0
def session
collection.database.session
collection.database.client
end
end
end
Expand Down
69 changes: 0 additions & 69 deletions lib/mongoid/contextual/find_and_modify.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/mongoid/contextual/geo_near.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def documents
#
# @since 3.0.0
def results

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be called result instead of results just because is returning one element, isn't it?

@results ||= session.command(command)
@results ||= session.command(command).first
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/mongoid/contextual/map_reduce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ def apply_criteria_options
# @since 3.0.0
def documents
return results["results"] if results.has_key?("results")
query = session[output_collection].find
query.no_timeout if criteria.options[:timeout] == false
query
view = session[output_collection].find
view.no_cursor_timeout if criteria.options[:timeout] == false
view
end

# Get the collection that the map/reduce results were stored in.
Expand Down Expand Up @@ -299,7 +299,7 @@ def output_collection
# @since 3.0.0
def results

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be called result instead of results just because is returning one element, the same as in geo_near.rb

raise Errors::NoMapReduceOutput.new(command) unless command[:out]
@results ||= __session__.command(command)
@results ||= __session__.command(command).first
end

# Get the session with the proper consistency.
Expand All @@ -316,7 +316,7 @@ def results
# @since 3.0.15
def __session__
if command[:out][:inline] != 1
session.with(read: :primary)
session.with(read: { mode: :primary })
else
session
end
Expand Down
Loading