Giter Site home page Giter Site logo

mongodb_tests's Introduction

Screencast - Docker + MongoDB + Admin/Création Collection/User/

Docker installation

asciicast asciicast

Docker running

asciicast asciicast

Docker pour MongoDB

Récupérer une image MongoDB

$ docker pull mongo:latest

Créer des dossiers permanents pour les bases de données MongoDB

$ sudo mkdir -p /opt/mongodb/db 

Lancer le server MongoDB en mode authentifié

$ docker run -p 27017:27017 -v /opt/mongodb/db:/data/db --name my-mongo-dev -d mongo mongod --auth

Vérification et logs

$ docker ps
$ docker logs -f my-mongo-dev

Lancer un client Mongo pour créer un super-admin

$ docker exec -it my-mongo-dev mongo

super-admin dans la console mongo

	use admin

	db.createUser(
		{
		user: "siteUserAdmin",
		pwd: "unPasswordQuiVaBien",
		roles: [{role: "userAdminAnyDatabase", db: "admin"}]
		}
	)

Ajouter un utilisateur pour notre base de données

Connection en super-admin

$ mongo -p 27017 -u siteUserAdmin --authenticationDatabase admin

Création de la base et d'un utilisateur (owner)

	use kanban

	db.createUser(
		{
			user: "kanbanUser",
			pwd: "unAutrePasswordQuiVaBien",
			roles: ["dbOwner"]
		}
	)

Test de connection à la base sur la collection avec le bon user

$ mongo --port 27017 -u kanbanUser -p kanban --authenticationDatabase kanban

Python: pymongo

http://api.mongodb.com/python/current/tutorial.html

from pymongo import MongoClient

client = MongoClient(
	'mongodb://{user}:{passwd}@{host}:{port}/kanban'.format(
		host='127.0.0.1',
		port=27017
		user='kanbanUser',
		passwd='unAutrePasswordQuiVaBien',
	)
)
db = client.kanban
kanban = db.kanban

for cur in kanban.find():
	print(cur)

Sources

urls:

mongodb_tests's People

Contributors

yoyonel avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.