 MEMO: reserved-namespace? ( name -- ? )
     [ "$cmd" = ] [ "system" head? ] bi or ;
     
-PRIVATE>
-
-MEMO: ensure-collection ( collection -- fq-collection )
+MEMO: check-collection ( collection -- fq-collection )
     dup mdb-collection? [ name>> ] when
     "." split1 over mdb-instance name>> =
     [ nip ] [ drop ] if


GENERIC: save ( collection assoc -- )
M: assoc save
    [ ensure-collection ] dip
    <mdb-insert-msg> send-message-check-error ;

GENERIC: save-unsafe ( collection object -- )
M: assoc save-unsafe
    [ ensure-collection ] dip
    <mdb-insert-msg> send-message ;

GENERIC: ensure-index ( collection name spec -- )

    check-ok [ "could not drop index" throw ] unless ;

: <update> ( collection selector object -- update-msg )
    [ check-collection ] 2dip <mdb-update-msg> ;

: >upsert ( mdb-update-msg -- mdb-update-msg )
    1 >>upsert? ; 
