Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix array building

  • Loading branch information...
commit 5c5404bdb3d3d5b96f0ddb5a0b17e851a2516e27 1 parent 43caa58
@mikejs authored
Showing with 14 additions and 3 deletions.
  1. +14 −3 bson.go
View
17 bson.go
@@ -386,9 +386,20 @@ func (bb *_BSONBuilder) OID(o []byte) { bb.Put(&_OID{o, _Null{}}) }
func (bb *_BSONBuilder) Key(key string) Builder {
bb2 := new(_BSONBuilder);
- bb2.obj = bb.Get().(*_Object).value;
- bb2.key = key;
- bb2.obj[key] = Null;
+
+ switch obj := bb.Get().(type) {
+ case *_Object:
+ bb2.obj = obj.value;
+ bb2.key = key;
+ bb2.obj[key] = Null;
+ case *_Array:
+ bb2.arr = obj.value;
+ elem, _ := strconv.Atoi(key);
+ bb2.elem = elem;
+ for elem >= bb2.arr.Len() {
+ bb2.arr.Push(Null)
+ }
+ }
return bb2;
}
Please sign in to comment.
Something went wrong with that request. Please try again.