diff --git a/bson/constants/constants.factor b/bson/constants/constants.factor index 039ea18089..368374fb30 100644 --- a/bson/constants/constants.factor +++ b/bson/constants/constants.factor @@ -11,6 +11,8 @@ TUPLE: oid { a initial: 0 } { b initial: 0 } ; TUPLE: objref ns objid ; +CONSTANT: MDB_OID_FIELD "_id" + CONSTANT: T_EOO 0 CONSTANT: T_Double 1 CONSTANT: T_Integer 16 diff --git a/bson/writer/writer.factor b/bson/writer/writer.factor index 439cfb7372..55adb95b11 100644 --- a/bson/writer/writer.factor +++ b/bson/writer/writer.factor @@ -93,9 +93,16 @@ M: sequence bson-write ( array -- ) [ length 5 + bson-write ] keep write write-eoo ; - + +: write-oid ( hashtable -- ) + [ MDB_OID_FIELD ] dip at* + [ [ MDB_OID_FIELD ] dip write-pair ] [ drop ] if ; inline + +: oid-field? ( name -- boolean ) + MDB_OID_FIELD = ; inline + M: assoc bson-write ( hashtable -- ) - '[ _ [ write-pair ] assoc-each ] + '[ _ [ write-oid ] [ [ over oid-field? [ 2drop ] [ write-pair ] if ] assoc-each ] bi ] binary swap with-byte-writer [ length 5 + bson-write ] keep write diff --git a/mongodb/operations/operations.factor b/mongodb/operations/operations.factor index e628251103..75207cf30b 100644 --- a/mongodb/operations/operations.factor +++ b/mongodb/operations/operations.factor @@ -120,7 +120,7 @@ M: mdb-reply-op (read-message) ( msg-stub opcode -- message ) read-longlong >>cursor read-int32 >>start# read-int32 [ >>returned# ] keep - [ stream>assoc drop ] accumulator [ times ] dip >>objects ; + [ H{ } stream>assoc drop ] accumulator [ times ] dip >>objects ; : read-header ( message -- message ) read-int32 >>length @@ -151,7 +151,7 @@ PRIVATE> write flush ; inline : build-query-object ( query -- selector ) - [let | selector [ ] | + [let | selector [ H{ } clone ] | { [ orderby>> [ "orderby" selector set-at ] when* ] [ explain>> [ "$explain" selector set-at ] when* ] [ hint>> [ "$hint" selector set-at ] when* ]