From dca0ec2e581f16403f5947d97a5fba59e29b4174 Mon Sep 17 00:00:00 2001 From: mark-roggenkamp-snapav Date: Wed, 31 Dec 2014 15:59:48 -0500 Subject: [PATCH] Fixed bug when using a renamed _id field and an update operation which replaces a documents fields entirely. --- lib/mosql/streamer.rb | 2 +- test/functional/streamer.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/mosql/streamer.rb b/lib/mosql/streamer.rb index 203d6c2..d630e96 100644 --- a/lib/mosql/streamer.rb +++ b/lib/mosql/streamer.rb @@ -241,7 +241,7 @@ def handle_op(op) keys = {} primary_sql_keys.each do |key| source = schema[:columns].find {|c| c[:name] == key }[:source] - keys[key] = selector[source] + keys[source] = selector[source] end log.debug("upsert #{ns}: #{keys}") diff --git a/test/functional/streamer.rb b/test/functional/streamer.rb index 2ef9647..43be94b 100644 --- a/test/functional/streamer.rb +++ b/test/functional/streamer.rb @@ -95,6 +95,18 @@ def build_streamer assert_equal(27, sequel[:sqltable].where(:_id => o['_id'].to_s).select.first[:var]) end + it 'handle "u" ops without _id and a renamed _id mapping' do + o = { '_id' => BSON::ObjectId.new, 'var' => 17 } + @adapter.upsert_ns('mosql_test.renameid', o) + + @streamer.handle_op({ 'ns' => 'mosql_test.renameid', + 'op' => 'u', + 'o2' => { '_id' => o['_id'] }, + 'o' => { 'goats' => 27 } + }) + assert_equal(27, sequel[:sqltable2].where(:id => o['_id'].to_s).select.first[:goats]) + end + it 'applies ops performed via applyOps' do o = { '_id' => BSON::ObjectId.new, 'var' => 17 } @adapter.upsert_ns('mosql_test.collection', o)