After MongoDB is installed, there is no user connection authorization authentication
Direct input MONGO into interactive mode on the console
Show DBS Use Databasenameshow collections
None of these basic commands are going to be a problem.
############################################
Add user authorization Authentication to MONGODB-----MONGO into interactive mode
Use admin # to switch to the admin database # displays theDataSet---------------- # View user data in System.users ----db.adduser ('name') ,'pwd'# Add an Administrator account
Then open vi/etc/mongodb.conf.
Find #auth=true and comment out
Then restart the MongoDB database service
Sudo/etc/init.d/mongodb restart
At this point, MongoDB's auth configuration is complete
#################################
Create a Nodejs app
Add a MongoDB Plugin
NPM Install Mongodb-save
Use
var Mongodb=require ('MongoDB'). Mongoclient, URL='Mongo://username:[email protected]:p ort/database?authmechanism=mongodb-cr&authsource=admin', assert=require ('assert'); Mongodb.connect (Url,function (err,db) {assert. Equal (Err,null); var col=db.collection ('Collection-name'); Col.find ({}). ToArray (function (err,data) {console.log (data); }) })
Where authmechanism is the authorization mechanism this can be viewed through the above Db.system.users.find ()
Reference Address: HTTP://MONGODB.GITHUB.IO/NODE-MONGODB-NATIVE/2.2/
Nodejs authorizing the connection to MongoDB