MongoLab with ReactiveMongo Authorization Problems - mongodb

I have a small connection routine which is as below:
val dbName = "myDb"
val user = "myUser"
val pass = "myPass"
val mongoDriver = new reactivemongo.api.MongoDriver()
val db = MyDBObject(
mongoDriver.connection(
Seq("XXXXX.mongolab.com:XXXXX"),
options = MongoConnectionOptions(authMode = ScramSha1Authentication),
authentications = List(Authenticate(dbName, user, pass))
),
dbName
)
I'm using this to create a new connection and then using this connection, I work with my documents. But the problem is that for some very strange reason, I could not get this to work!
Here is the error that I get:
CommandError[code=13, errmsg=not authorized on myDb to execute command {....,
code: BSONInteger(13)
}]
I've been trying to dig into this for almost 3 hours without any vail! The MongoLab uses 3.0 version of MongoDB and I use 0.11.7 version for the ReactiveMongo library.
Using the mongo shell, I'm able to log in to the MongoLab and create new collections with the same set of credentials!

Related

Is it possible writing down to RDS raw sql (PostgreSQL) using AWS/Glue/Spark shell?

I have a Glue/Connection for an RDS/PostgreSQL DB pre-built via CloudFormation, which works fine in a Glue/Scala/Sparkshell via getJDBCSink API to write down a DataFrame to that DB.
But also I need to write down to the same db, plain sql like create index ... or create table ... etc.
How can I forward that sort of statements in the same Glue/Spark shell?
In python, you can provide pg8000 dependency to the spark glue jobs and then run the sql commands by establishing the connection to the RDS using pg8000.
In scala you can directly establish a JDBC connection without the need of any external library as far as driver is concerned, postgres driver is available in aws glue.
You can create connection as
import java.sql.{Connection, DriverManager, ResultSet}
object pgconn extends App {
println("Postgres connector")
classOf[org.postgresql.Driver]
val con_st = "jdbc:postgresql://localhost:5432/DB_NAME?user=DB_USER"
val conn = DriverManager.getConnection(con_str)
try {
val stm = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
val rs = stm.executeQuery("SELECT * from Users")
while(rs.next) {
println(rs.getString("quote"))
}
} finally {
conn.close()
}
}
or follow this blog

Meteor MongoDB database localhost vs server

I made a site with Meteor and it works perfectly on localhost, but not on the server. I have a collection in my mongoDB that I fill using a python-script, this script filled both my local as server mongoDB. I can see that it is filled using a database manager. However the call in my localhost prints an array with the documents, the same code/action on the website on the server returns an empty array.
I really have no clue what the problem could be, somebody that can help me figure this out?
python-script, same for local as on server!
def write_data(documents, collection_name):
# when running locally
#client = pymongo.MongoClient("localhost", 3001)
#db = client.meteor
# on the server
client = MongoClient(mongoURL, username=****,
password=****)
db = client.mercurius
if collection_name in db.collection_names():
collection = db[collection_name]
collection.drop()
new_collection = db[collection_name]
new_collection.insert_many(documents)
cursor = new_collection.find({})
for document in cursor:
print(document)
I use mup to setup the containers, it works for the other things, my code. mongoURL in mup is same as in this script above.
Meteor.call( 'getDBinfo', function(err, response){
console.log(response);
console.log(err);
});
The above call in meteor returns a full array(53 documents) on localhost, empty on server. Both have an undefined err.

How to change Pymongo database connection

I do have a database named users but pymongo is looking for a db named as app is there any way to change to Pymongo connection method ?
this one is working if i crate a db named as app;
app = Flask(__name__)
mongo = PyMongo(app)
i want to connect like this but i do get an error for that ;
mongo = PyMongo('users')
I have found my answer;
client = MongoClient('localhost')
db = client['dbname']
collection = db.collection_name
app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'dbname'
mongo = PyMongo(app)
This allows you to use flask_pymongo, more info here

Mongo get db.serverstatus from casbah

Is there a way to get the results of
db.serverStatus()
from casbah to handle them?
I specifically need the connections, network, metrics fields.
Thanks
import com.mongodb.casbah.Imports._
//connect to MongoDB, testDB is the name of database
val test = MongoClient()("testDB")
// run serverStatus command
val status = test.command("serverStatus")
// status is an instance of BasicDBObject
//retrieving number of available connections
val availableConnections = status.get("connections").asInstanceOf[BasicDBObject].get("available")

Connecting to a MongoDb in Node.js Error

Quite simply, I'm trying to connect to a MongoDB via Node.js:
Db = require('../v2/node_modules/mongodb').Db
Connection = require('../v2/node_modules/mongodb').Connection
Server = require('../v2/node_modules/mongodb').Server
console.log "before"
DbServer = new Server("localhost", 27017, {})
db = new Db("twitter", DbServer, {native_parser:true})
console.log "after"
return
That's my code and it's as simple as it gets. My output, however, seems to stop at the db = new Db... line.
It never gets to the after. It doesn't give an error either. I know I have a DB running and when I fire up MongoHub, it's there along with the twitter database
Just remove the native_parser=true would be ok
Native bson parser not compiled, please compile or avoid using native_parser=true