Skip to content
This repository was archived by the owner on Dec 22, 2020. It is now read-only.

Commit 8043b96

Browse files
Implement BSON::DBRef support.
closes #50
1 parent 2e86950 commit 8043b96

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/mosql/schema.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ def transform(ns, obj, schema=nil)
176176
case v
177177
when BSON::Binary, BSON::ObjectId, Symbol
178178
v = v.to_s
179+
when BSON::DBRef
180+
v = v.object_id.to_s
179181
when Hash
180182
v = JSON.dump(v)
181183
when Array

test/unit/lib/mosql/schema.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ class MoSQL::Test::SchemaTest < MoSQL::Test
170170
assert_equal(["row 1", nil, 'stringy', [1,2,3]], out)
171171
end
172172

173+
it 'extracts object ids from a DBRef' do
174+
oid = BSON::ObjectId.new
175+
out = @map.transform('db.collection', {'_id' => "row 1",
176+
'str' => BSON::DBRef.new('db.otherns', oid)})
177+
assert_equal(["row 1", nil, oid.to_s, nil], out)
178+
end
179+
173180
it 'changes NaN to null in extra_props' do
174181
out = @map.transform('db.with_extra_props', {'_id' => 7, 'nancy' => 0.0/0.0})
175182
extra = JSON.parse(out[1])

0 commit comments

Comments
 (0)