package com.jxy.marketall.config.mongodb;

import lombok.Data;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;

/**
 * @Description TODO
 * @Date 2023/4/17 18:46
 * @Author 杜懿
 */
@Data
public abstract class AbstractMongoDbConfig {
    private String host;
    private String port;
    private String username;
    private String password;
    private String database;
    public MongoDatabaseFactory mongoDatabaseFactory() {
        String connectionString = "mongodb://" + username + ":" + password+ "@"+ host+":"+port +"/" + database;
        return new SimpleMongoClientDatabaseFactory(connectionString);
    }

    public MongoDatabaseFactory mongoDatabaseNoUserFactory() {
        String connectionString = "mongodb://"+ host+":"+port +"/" + database;
        return new SimpleMongoClientDatabaseFactory(connectionString);
    }
    public abstract MongoTemplate getMongoTemplate();
}
