MongoDB fixed collection, establishing Administrator security authentication

Source: Internet
Author: User
Tags rar administrator password

Set up common set db.createcollections AAA; Fixed set name book capped true fixed collection size Max: Number of documents Db.createcollection ("book", {capped:true, Size:10000,max:5}) "capped": false, indicates normal collection

Normal collections can be converted to fixed setsdb.user.convertToCapped (MaxBytes)-Calls {converttocapped: ' user ', size:MaxBytes}} Command

View the status of the collection db.aa.stats (); Delete Book collection db.book.drop (); Take out the file Mongofiles.exe get C:/myb.js

Auth Security Verification


Create Super Admin > Db.createuser ({User: ' admin ', pwd: ' 123 ', roles:[' root '}); Successfully added User: {"user": "admin", "Roles": ["root"]} Admin login verification via > use admin;switched to DB admin> Db.aut H (' admin ', ' 123 ');1>
Super Admin directly login server MONGO--host localhost--port 27017--username admin--password 123--authenticationdatabase Adminmongo--hos T 192.168.2.3--port 27017--username admin--password 123--authenticationdatabase Admin
Streamlined login I:\mongodb\bin>mongo localhost:27017/admin-u admin-p 123
Modify the Super Administrator password use admin;db.updateuser (' admin ', {pwd: ' admin '});
Create a database administrator, > Use hndb;switched to DB hndb> db.createuser ({User: ' AA ', pwd: ' AA ', roles:[' read '});
"ReadOnly": true; Indicates read-only "readOnly": false; Represents a super administrator created

Login HNDB Vault Administrator account password F:\mongodb\bin>mongo localhost:27017/hndb-u aa-p AA
Only the HNDB library can be used
MongoDB Loop Statement Output 0-20
  
 
  1. var i=20;
  2. print(i);
  3. var i=0;
  4. while(i<10){
  5. print(i);
  6. i++;
  7. };

Query the database name all listed
  
 
  1. var rs=db.student.find({},{_id:0,name:1,age:1});
  2. while(rs.hasNext()){
  3. print(rs.next().name);
  4. }

Show name and age
  
 
  1. Span class= "KWD" >var RS = db Span class= "pun". student find _id 0 name : 1 age : 1
  2. while(rs.hasNext()){
  3. var o=rs.next();
  4. print("姓名"+o.name +",年龄"+o.age);
  5. }

Put the f.rar of the C drive into the database F:\mongodb\bin>mongofiles.exe put C:/f.rar list all the information F:\mongodb\bin>mongofiles.exe list
Export File F:\mongodb\bin>mongofiles.exe get C:/f.rar
View upload list Information view fs.files content can log in later Db.fs.files.find ();

Import and export of data read only the name age field mongoexport/h localhost/port 27017/authenticationdatabase:admin/u admin/p admin/d hndb/c stude nt/o c:\j.js/f Name,age
Export all properties, all fields read out mongoexport/h localhost/port 27017/authenticationdatabase:admin/u admin/p admin/d hndb/c s/o c \ J.js Delete the table inside the database use hndb;> db.student.drop ();

Then the data is imported mongoimport/h localhost/port 27017/authenticationdatabase:admin/u admin/p admin/d hndb/c student C:\j.js
Remove condition Delete Partial content > db.student.remove ({age:{$gte: 70}});
Remove part of the content and then import, the original does not understand, no new content will be added and then log in and then view
















From for notes (Wiz)

MongoDB fixed collection, establishing Administrator security authentication

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.