logo
down
shadow

Powershell Mongodb Authentication


Powershell Mongodb Authentication

By : Cindy
Date : November 17 2020, 11:52 AM
wish of those help Here is a snippet of MongoDb authentication from Powershell.
I use here MongoDB C# driver (have a look here)
code :
# Mongo DB driver
Add-Type -Path 'C:\Path_To_mongocsharpdriver\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Bson.dll'
Add-Type -Path 'C:\Path_To_mongocsharpdriver\mongocsharpdriver.1.9.2\lib\net35\MongoDB.Driver.dll'

# Connexion to MongoDB
$connectionString = "mongodb://user1:password1@localhost"
$db =  "MyDBName"
$collection =  "MyCollectionName"

function Get-MongoDBCollection ($connectionString, $db, $collection)
{
  $mongoClient = New-Object MongoDB.Driver.MongoClient($connectionString)
  $mongoServer = $mongoClient.GetServer()
  $mongoDatabase = $mongoServer.GetDatabase($db)
  $mongoCollection = $mongoDatabase.GetCollection($collection)
  return $mongoCollection
}

$FileName = $args[0]
# get the file name 
$FileNameLeaf = Split-Path $FileName -Leaf

# Connect to MongoDB and get collection
$mongoCollection = Get-MongoDBCollection $connectionString $db $collection

# Verify if this file is integrated
$query = New-Object MongoDB.Driver.QueryDocument('Fic_Data', $FileNameLeaf)
$found = $mongoCollection.FindOne($query)
if ($found -ne $null)
{
  Write-Host "`tThe file $FileNameLeaf is integrated !"
  return
}


Share : facebook icon twitter icon
Golang and MongoDb remote access fail (server returned error on SASL authentication step: Authentication failed.)

Golang and MongoDb remote access fail (server returned error on SASL authentication step: Authentication failed.)


By : Sedthee Sathaporn
Date : March 29 2020, 07:55 AM
Any of those help Please check if you have added users for your Mongolab database instance (https://mongolab.com/databases/catalog#users in case if your DB name is catalog) because by default your users list is empty (account user/password != database user/password).
Also add / to the end of your connection string - mongodb://*******:*******@ds045795.mongolab.com:45795/databasename.
Java MongoDB Client: authentication failed when access to a server not configured to use an authentication

Java MongoDB Client: authentication failed when access to a server not configured to use an authentication


By : Christoph Hackenberg
Date : March 29 2020, 07:55 AM
it should still fix some issue I am afraid not, your client does not know whether the server has auth enabed or not.
Your client connection code should match the auth parameters from the server, otherwise it fails.
spring-data-mongodb giving mongodb authentication exception

spring-data-mongodb giving mongodb authentication exception


By : William Mangoni
Date : March 29 2020, 07:55 AM
This might help you Please use the below application context and try to connect to MongoDB. It should work. The main thing missing in your application context is "AuthenticationMechanism" (i.e. value is SCRAM-SHA-1). Just to add the correct authentication mechanism, we may need to take this approach.
I have reproduced the issue and resolved it using the below context file. Hopefully, this should fix the issue.
code :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/mongo
        http://www.springframework.org/schema/data/mongo/spring-mongo.xsd">

    <context:annotation-config />

    <bean id="mongoSeedListID" class="java.util.ArrayList">
        <constructor-arg>
            <list>
                <ref bean="mongoSeedlID" />
            </list>
        </constructor-arg>
    </bean>

    <bean id="mongoSeedlID" class="com.mongodb.ServerAddress">
        <constructor-arg type="java.lang.String" name="host"
            value="localhost" />
        <constructor-arg type="int" name="port" value="27017" />
    </bean>

    <bean id="mongoCredentialListID" class="java.util.ArrayList">
        <constructor-arg>
            <list>
                <ref bean="mongoCredentialID" />
            </list>
        </constructor-arg>
    </bean>

    <bean id="mongoCredentialID" class="com.mongodb.MongoCredential">
        <constructor-arg name="mechanism"
            value="#{T(com.mongodb.AuthenticationMechanism).SCRAM_SHA_1}" />
        <constructor-arg type="java.lang.String" name="userName"
            value="admin" />
        <constructor-arg type="java.lang.String" name="source"
            value="myDb" />
        <constructor-arg type="char[]" name="password" value="password" />
    </bean>

    <bean id="mongoClientID" class="com.mongodb.MongoClient">
        <constructor-arg ref="mongoSeedListID" />
        <constructor-arg ref="mongoCredentialID" />
    </bean>

    <bean id="simpleMongoDbFactoryID"
        class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
        <constructor-arg ref="mongoClientID" />
        <constructor-arg name="databaseName" value="myDb" />
    </bean>

    <bean class="org.springframework.data.mongodb.core.MongoFactoryBean"
        id="mongo">
        <property name="host" value="localhost" />
        <property name="port" value="27017" />
    </bean>

    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg ref="simpleMongoDbFactoryID" />
    </bean>

</beans>
Laravel with MongoDB only or MongoDB + MySQL for authentication?

Laravel with MongoDB only or MongoDB + MySQL for authentication?


By : shiv kumar
Date : March 29 2020, 07:55 AM
may help you .
I'm building a Laravel app. My data requires me to have a mongoDB database, so I'm building the app with Laravel + MongoDB. Works well so far, but when condidering user authentication, I'm not sure Mongo is the best option, so I'm divided between using Mongo or having an extra Mysql database just for user auth.
MongoDB: server returned error on SASL authentication step: Authentication failed

MongoDB: server returned error on SASL authentication step: Authentication failed


By : user3078400
Date : March 29 2020, 07:55 AM
help you fix your problem The problem solved by changing localhost to the name of mongo container which is mongo, too.
Now the following code can be run successfully:
code :
version: '3'

services: 
  mongo:
    image: mongo
    container_name: mongo
    restart: always
    environment: 
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

  prometheus:
    image: prom/prometheus
    container_name: prometheus
    restart: always
    ports:
      - 9090:9090
    volumes:
      - /home/mostafa/Desktop/docker_lab/mongo/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
    command: 
      - '--config.file=/etc/prometheus/prometheus.yml'

  mongodb-exporter:
    build: .
    container_name: mongodb_exporter
    command: ./mongodb_exporter-linux-amd64 -logtostderr -mongodb.uri mongodb://mongo:27017 -groups.enabled 'asserts,durability,background_flusshing,connections,extra_info,global_lock,index_counters,network,op_counters,op_counters_repl,memory,locks,metrics'
    restart: always
    ports: 
      - 9001:9001
Related Posts Related Posts :
  • Why do we need an 'arbiter' in MongoDB replication?
  • How to create tree like compound index in mongodb
  • Call stored function in mongodb
  • Mongodb update deeply nested subdocument
  • how do non-ACID RethinkDB or MongoDB maintain secondary indexes for non-equal queries
  • How to set "arbiterOnly" to an existing node in a replicaset, from MongoDB MMS portal?
  • MongoDB: Using $geoIntersects or $geoWithin with $near in one query
  • [METEOR $addToSet]Cannot insert into object '$addToSet' is empty
  • How to increment a field in mongodb?
  • "For" loop with meteor
  • howto route with collection's param in iron router Meteor JS
  • Connect to MongoDB on Azure (from client)
  • Aggregating filter for Key
  • Consequences of using $unwind on nested arrays?
  • Set operation with condition
  • How to create database schema for multiuser application (No SQL)
  • MongoDB data files created in wrong directory while changing oplog size
  • mongodb , wildcard in $in
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org