fixed bug in bson.writer which caused any field name "_id" to be written twice,

fixed lasterror in mongodb.driver
db4
Sascha Matzke 2009-03-05 07:01:12 +01:00
parent 208620336f
commit 87f0eeb282
3 changed files with 11 additions and 8 deletions

View File

@ -3,7 +3,7 @@
USING: accessors assocs bson.constants byte-arrays fry io io.binary
io.encodings.binary io.encodings.string io.encodings.utf8
io.streams.byte-array kernel math math.parser quotations sequences
serialize strings words ;
serialize strings words tools.hexdump ;
IN: bson.writer
@ -99,11 +99,13 @@ M: sequence bson-write ( array -- )
[ [ MDB_OID_FIELD ] dip write-pair ] [ drop ] if ; inline
: skip-field? ( name -- boolean )
{ MDB_OID_FIELD MDB_INTERNAL_FIELD } member? ; inline
{ "_id" "_mdb" } member? ; inline
M: assoc bson-write ( assoc -- )
'[ _ [ write-oid ] [ [ over skip-field? [ 2drop ] [ write-pair ] if ] assoc-each ] bi ]
binary swap with-byte-writer
[ binary ] dip
'[ _ [ write-oid ] keep
[ over skip-field? [ 2drop ] [ write-pair ] if ] assoc-each
] with-byte-writer
[ length 5 + bson-write ] keep
write
write-eoo ;

View File

@ -1,6 +1,6 @@
USING: accessors assocs fry io.sockets kernel math mongodb.msg formatting linked-assocs destructors continuations
mongodb.operations namespaces sequences splitting math.parser io.encodings.binary combinators io.streams.duplex
arrays io memoize constructors sets strings ;
arrays io memoize constructors sets strings uuid ;
IN: mongodb.driver
@ -231,7 +231,7 @@ M: assoc count
: lasterror ( -- error )
cmd-collection H{ { "getlasterror" 1 } } <mdb-query-msg>
find-one objects>> [ "err" ] at ;
find-one objects>> first [ "err" ] dip at ;
GENERIC: validate ( collection -- )
M: string validate
@ -262,6 +262,7 @@ M: assoc save-unsafe
GENERIC: ensure-index ( collection name spec -- )
M: assoc ensure-index
H{ } clone
[ [ uuid1 "_id" ] dip set-at ] keep
[ [ "key" ] dip set-at ] keep
[ [ "name" ] dip set-at ] keep
[ [ index-ns "ns" ] dip set-at ] keep

View File

@ -1,7 +1,7 @@
USING: accessors fry io io.encodings.binary io.servers.connection
io.sockets io.streams.byte-array kernel math mongodb.msg classes formatting
mongodb.msg.private namespaces prettyprint tools.walker calendar calendar.format
json.writer ;
namespaces prettyprint tools.walker calendar calendar.format
json.writer mongodb.operations.private mongodb.operations ;
IN: mongodb.mmm