pub fn into_document(self) -> Document {
        // If document is missing "name" we follow default name generation as described in mongodb doc and
        // add it.
        // https://docs.mongodb.com/manual/indexes/#index-names
        // > The default name for an index is the concatenation of the
        // > indexed keys and each key’s direction in the index ( i.e. 1 or -1)
        // > using underscores as a separator.

        let mut names = Vec::with_capacity(self.keys.len());
        let mut keys_doc = Document::new();
        for key in self.keys {
            let key_name = match key.direction {
                SortOrder::Ascending => format!("{}_1", key.name),
                SortOrder::Descending => format!("{}_-1", key.name),
            };
            names.push(key_name);

            keys_doc.insert(key.name, key.direction);
        }

        let mut index_doc = doc! { "key": keys_doc };

        for option in self.options {
            let (key, value) = option.into_key_value();
            index_doc.insert(key, value);
        }

        if !index_doc.contains_key("name") {
            let name = names.join("_");
            index_doc.insert("name", name);
        }

        index_doc
    }
/// Convert this structure into a `Document` version structured as expected by mongo.
Convert this structure into a `Document` version structured as expected by mongo.
Convert this structure into a ` Document ` version structured as expected by mongo .
pub fn into_document(self) -> Document {
        // If document is missing "name" we follow default name generation as described in mongodb doc and
        // add it.
        // https://docs.mongodb.com/manual/indexes/#index-names
        // > The default name for an index is the concatenation of the
        // > indexed keys and each key’s direction in the index ( i.e. 1 or -1)
        // > using underscores as a separator.
        let mut names = Vec::with_capacity(self.keys.len());
        let mut keys_doc = Document::new();
        for key in self.keys {
            let key_name = match key.direction {
                SortOrder::Ascending => format!("{}_1", key.name),
                SortOrder::Descending => format!("{}_-1", key.name),
            };
            names.push(key_name);
            keys_doc.insert(key.name, key.direction);
        }
        let mut index_doc = doc! { "key": keys_doc };
        for option in self.options {
            let (key, value) = option.into_key_value();
            index_doc.insert(key, value);
        }
        if !index_doc.contains_key("name") {
            let name = names.join("_");
            index_doc.insert("name", name);
        }
        index_doc
    }
pub fn into_document ( self ) -> Document { // If document is missing "name" we follow default name generation as described in mongodb doc and // add it. // https://docs.mongodb.com/manual/indexes/#index-names // > The default name for an index is the concatenation of the // > indexed keys and each key’s direction in the index ( i.e. 1 or -1) // > using underscores as a separator. let mut names = Vec :: with_capacity ( self . keys . len ( ) ) ; let mut keys_doc = Document :: new ( ) ; for key in self . keys { let key_name = match key . direction { SortOrder :: Ascending => format ! ( " " key name ) , SortOrder :: Descending => format ! ( " " key name ) , } ; names . push ( key_name ) ; keys_doc . insert ( key . name , key . direction ) ; } let mut index_doc = doc ! { " " keys_doc } ; for option in self . options { let ( key , value ) = option . into_key_value ( ) ; index_doc . insert ( key , value ) ; } if ! index_doc . contains_key ( " " ) { let name = names . join ( " " ) ; index_doc . insert ( " " , name ) ; } index_doc }
Convert this structure into a `Document` version structured as expected by mongo.
Convert this structure into a ` Document ` version structured as expected by mongo .
self