 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

    [ [ (ensure-collection) ] keep ] unless
    [ mdb-instance name>> ] dip "%s.%s" sprintf ; inline

: <query> ( collection query -- mdb-query )
    [ ensure-collection ] dip
    <mdb-query-msg> ; inline

GENERIC# limit 1 ( mdb-query limit# -- mdb-query )

    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? ; 
