 
 GENERIC: save ( collection assoc -- )
 M: assoc save
-    [ ensure-collection ] dip
+    [ check-collection ] dip
     <mdb-insert-msg> send-message-check-error ;
 
 GENERIC: save-unsafe ( collection object -- )
 M: assoc save-unsafe
-    [ ensure-collection ] dip
+    [ check-collection ] dip
     <mdb-insert-msg> send-message ;
 
 GENERIC: ensure-index ( collection name spec -- )

MEMO: reserved-namespace? ( name -- ? )
    [ "$cmd" = ] [ "system" head? ] bi or ;
    
PRIVATE>

MEMO: ensure-collection ( collection -- fq-collection )
    dup mdb-collection? [ name>> ] when
    "." split1 over mdb-instance name>> =
    [ nip ] [ drop ] if

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

GENERIC: delete-unsafe ( collection selector -- )
M: assoc delete-unsafe
    [ check-collection ] dip
    <mdb-delete-msg> send-message ;

: load-index-list ( -- index-list )
    index-collection
    H{ } clone <mdb-query-msg> find nip ;

: ensure-collection ( name -- )
    check-collection drop ;

: drop-collection ( name -- )
    [ cmd-collection ] dip
