Connect MLAB Mongo instance using mongosqld command

Hi,

Lot’s of folk are wondering how to connect the MLAB mongo instance using mongosqld so they can connect it via ODBC to Power BI or Tableau. For the full tutorial, you can visit this link https://blog.knesk.com/mongodb-can-not-connect-the-database-by-mongodb-odbc-driver-windows/

This article only intends to connect the MLAB mongo instance via mongosqld command as usual command will not work with MLAB because mogosqld command tries to connect to admin DB which you don’t have permission to access if you are using mlab. So if you try to connect mlab instance via usual mongosqld query it will throw an error

error initializing schema: error listing databases: error listing databases: (Unauthorized) not authorized on admin to execute command { listDatabases: 1, $db: "admin", $readPreference: { mode: "primary" } }

So in order to connect via mongosqld you need to generate the SCHEMA file beforehand and the define the schema file with mongosqld command so here are the steps:

Step1: Generate the Schema file

mongodrdl  sample --db mydb --out D:\schema.drdl --host "ds261644.mlab.com" --port 61644 -u lucian -p pass123 --authenticationDatabase mydb

Step2: Connect via mongosqld

mongosqld --mongo-uri "mongodb://ds261644.mlab.com:61644" --schema D:\schema.drdl --auth -u lucian -p pass123 --mongo-authenticationSource mydb --defaultAuthSource mydb -v

MongoDB – Can not connect the database by Mongodb ODBC Driver Windows

Hello Friends,

So many users are complaining that they cannot connect to the Mongodb with the ODBC Driver so today I am gonna write this tutorial as I was also stuck with the MongoDB ODBC connector issue on windows and did not find any help over the internet. So after debugging lots of hours i finally able to connect with the MongoDB ODBC with my server. So, first of all, you need to download these prerequisites.

Step 1: Prerequisites

Step 2: Connecting to Database via mongosqld

mongosqld --mongo-uri "mongodb://13.251.86.51:27017" --auth --mongo-username lucifer --mongo-password Pass1234 --mongo-authenticationSource admin
  • Open Command Prompt and run the above query until it fully samples the whole schema and shows you all the collections names in the cli like this

Step 3: Connecting via ODBC

Now Test the connection. That’s all. 🙂

Golang — Extract value from interfaces{} without specifying the Struct Type

Let say you pass struct as an interface argument to function and you do not have access to the type struct then how to extract the fields values.

Now you are trying to figure out why the heck i need to do this, lol. But there are many cases where you do not have access to the TYPE.

Let’s take an example i am building a go pkg and i want user to specify there own Table Struct but on my pkg i want to access the values of that struct which i do not have access to directly.

Live Example: https://play.golang.org/p/73OH5zYxjAF

package main
import (
 "fmt"
 "reflect"
)
type User struct {
 UserEmail string
 UserPass  string
}
func login(user interface{}) {
 
 ////--- Extract Value without specifying Type
 val := reflect.ValueOf(user).Elem()
 n := val.FieldByName("UserEmail").Interface().(string)
 fmt.Printf("%+v\n", n)
 
 fmt.Println(user.(*User).UserEmail)
}
func main() {
 login(&User{UserEmail: "[email protected]", UserPass: "lucian123"})
}

×