
classdef Database < handle
    properties
        hostname;
        username;
        password;
        database='poc';
        port=27017;
        mongo;
    end
    
    methods
        function obj = Database(hostname, username, password)
            javaaddpath 'mongo-java-driver-3.4.2.jar';
            import com.mongodb.*;
            obj.hostname = hostname;
            obj.username = username;
            obj.password = password;
            credential = MongoCredential.createCredential(obj.username, obj.database, obj.password);
            obj.mongo = MongoClient(obj.hostname, obj.port);
%             obj.mongodbconn = mongodatabase(hostname, obj.port, obj.database, 'UserName', username, 'Password', password); %#ok<*NOPTS>
        end
    end
    
    methods(Static)
        function test
            db = Database('localhost', 'poc_java', 'HenryPump@1903');
            database = db.mongo.getDatabase(db.database);
            database.auth(db.username, db.password);
            cards = database.getCollection('cards');
            
            cards.count()
        end
    end
    
    
end