access Mongo replicaset through meteor using username and password - meteor

I am using mongo replicaset through my meteor app.
Here is my connection string and code:
var collectionsDB = new MongoInternals.RemoteCollectionDriver("mongodb://usr:pwd#10.9.111.111:27017,user:pwd#10.9.111.112:27017,use:pwd#10.9.111.113:27017/myDB?replicaSet=myRelicaset&authSource=myDB&readPreference=primaryPreferred&w=1");
coll = new Mongo.Collection('<myCollection>',{ _driver:collectionsDB });
Problem:
When I am trying to insert to mongoDB, it tries to insert into Admin db rather myDB. The user usr has readwrite permission for myDB. I fail to understand why it is targeting Admin. As it does not have permission in Admin it through permission error.
However it works fine for individual mongo server without replicaset.
Any thing I am missing in connection string?
thanks
Nihar

Related

Use last interactive login profile to connect to Azure Analysis Service with Adomd client

I successfully connected to my org AAS database with Adomd .NET client library
using Microsoft.AnalysisServices.AdomdClient;
Console.WriteLine("Starting program...");
AdomdConnection adomdConnection = new AdomdConnection("Provider=MSOLAP;Data Source=asazure://<OrgAAS>;Initial Catalog=<DataCube>;");
adomdConnection.Open();
foreach (CubeDef cube in adomdConnection.Cubes)
{
Console.WriteLine(cube.Name);
foreach (Dimension dim in cube.Dimensions)
{
Console.WriteLine(dim.Name);
}
foreach (Measure measure in cube.Measures)
{
Console.WriteLine(measure.Name);
}
}
Console.WriteLine("Closing program...");
adomdConnection.Close();
However, it keeps prompting me to login every time I launch the program (I only need to select the profile). According to this document https://learn.microsoft.com/en-us/azure/analysis-services/analysis-services-connect, Integrated Azure Active Directory authentication will use credential cache if available, but it seems the program didn't cache the credential when I login.
Can I cache the credential so that the prompt windows doesn't appear and prompt me to select the profile everytime I launch?
Also, can I use this set up for my server? Can I set up something like Device code Authentication flow in here https://learn.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows?

AWS EC2 IAM role for S3 access not working

I have an asp.net website running on an EC2 instance, this instance has an IAM role assigned to it with the AmazonS3FullAccess policy. This works fine for the website where I can upload, delete and get presigned URL's for images stored in my S3 bucket.
On the same EC2 instance I also have an asp.net API for a mobile application to access various data. When I try to get a presigned URL for an image stored in S3 using the API the following error is thrown.
Object reference not set to an instance of an object.
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
at Amazon.S3.AmazonS3Client.GetPreSignedURLInternal(GetPreSignedUrlRequest request, Boolean useSigV2Fallback)
The code for getting the presigned link is the same for the website and the API
Dim bucketRegion = RegionEndpoint.EUWest1
Dim s3Client As New AmazonS3Client(bucketRegion)
Dim request1 = New GetPreSignedUrlRequest
request1.BucketName = "mybucketname"
request1.Key = fileName
request1.Expires = DateTime.Now.AddMinutes(1080)
dim signedURL = s3Client.GetPreSignedURL(request1)
The error is thrown on the GetPreSignedURL line.
I can't figure out why the IAM role permissions work for the website but not the API hosted on the same server.
iam role does not have credentials locally and for creating the presigned url we need to have credentials.
aws iam get credentials asynchronously.
So, we should call the presigned url function asynchronously if we are using iam role.
reference:
for .net :
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/index.html
for Nodejs:
https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property

how to assign roles to users with meteor?

how to assign roles to users with meteor?
I installed the package meteor add alanning: roles, and then I went into command prompt and typed the meteor command shell to access the meteor console server side. and i typed this code:
Var = myId Meteor.users.findOne ({username: "Elsa"}) ._ id
Roles.addUsersToRoles (myId, [ 'admin'])**
to assign the right to the admin user and Elsa in Mongolia I see no added admin roles in the collection
If you use the package
https://github.com/alanning/meteor-roles
Please be sure that username in database is unique.
Try these inside Meteor.startup code much before in server folder, place these
var id = Meteor.users.findOne({username: "Elsa"});
Roles.addUsersToRoles(id._id, ['admin'], 'default-group');
Hope these help

Failed to authenticate credentials using Mongolite R

I use R and trying to use the very recent "Mongolite". However I cannot connect to MongoDB server.
The manual clearly states the following:
mongo(collection = "test", db = "test", url = "mongodb://localhost")
This is what I have tried without success, where I have a log token and the port of course.
mongodb://heroku:TOKEN#lennon.mongohq.com:PORT
and keep getting the following error:
Error in mongo_collection_new(url, db, collection) :
Failed to authenticate credentials.
It is tried and true that mongolite (v0.7 as of today) supports authenticated connection to a remote 3.2.x MongoDB (as opposed to localhost).
The example below jeroenooms provides himself worked:
library(mongolite)
mongo(collection = "mtcars", url = "mongodb://readwrite:test#ds043942.mongolab.com:43942/jeroen_test")
To explain:
mtcars is the name of the MongoDB "collection" (or "table" if you insist). It could be a name that does not exist yet.
readwrite is the user name of your mongodb
test is the password of the user "readwrite"
ds043942.mongolab.com is the remote host, which could be replaced by ip address, i.e. 23.20.234.21
43942 is the port number. By default in MongoDB, it is 27017
jeroen_test is the name of the database instance in use, which has to exist already
Running the commands above in R will print:
Mongo Message: SCRAM: authenticating "readwrite" (step 1)
Mongo Message: SCRAM: authenticating "readwrite" (step 2)
Mongo Message: SCRAM: authenticating "readwrite" (step 3)
Mongo Message: SCRAM: "readwrite" authenticated
...
I tried to replace it with my own remote host info. It didn't work in the beginning, which turned to be the user role issue rather than mongolite issue. After ensuring a user with correct readWrite roles, I connected to my remote 3.2.x MongoDB via mongolite package.
The following 2 sources were of great help to me in setting up users in MongoDB:
enable-authentication
Manage User and Roles
If you look into the source code of jeroenooms/mongolite you can see that it doesn't support authentication yet:
https://github.com/jeroenooms/mongolite/blob/master/R/mongo.R
mongo_collection_new <- function(uri = "mongodb://localhost", db = "test", collection = "test"){
stopifnot(is.character(uri))
stopifnot(is.character(db))
stopifnot(is.character(collection))
.Call(R_mongo_collection_new, uri, db, collection)
}
just change the order :
mongo( url = "mongodb://localhost",db = "test",collection = "test")
I found that the following command allowed me to connect to mongodb using mongolite and the legacy SCRAM-SHA-1 authentication mode.
library(mongolite)
mongoUrl <- "mongodb://a_username:a_password#localhost:27017/admin" #<-admin here is the mongodb database that stores the authentication info
# specify your collection
colname <- "a_collection"
# specify your database
dbname <- "a_database"
# create connection (con)
con <- mongo(collection = colname, url = mongoUrl, db=dbname)
# count how many records (fyi this is just a test)
con$count('{}')

Cannot create new connection or login to added user?

I am using Oracle SQL Developer to connect to Oracle Express 11g and create a new user. I keep on getting the same error when I try to create a new connection (and test it) or when I try to login with a newly created username and password (mad by right-clicking "other users" table in default connection "xe")
The error-
Failure - Test Failed: ORA-01017: invalid username/password; logon denied
How can I fix this issue ?
Seems you're using an user with not enough privilegies, try with "system" user.
That should solve your problem.
Verify the priviligies of the user you created.

Resources