Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
development:database:mongodb [2020/10/23 12:11]
kalenpw
development:database:mongodb [2021/07/06 10:13] (current)
kalenpw
Line 4: Line 4:
  
 ===== Basics ===== ===== Basics =====
-Runs on port:  27017+Runs on port:  ''27017'' 
 + 
 +---- 
 +===== Show databases ===== 
 +<code mongodb> 
 +show dbs 
 +</code> 
 + 
 +---- 
 +===== Create DB ===== 
 +<code mongodb> 
 +use db_name # if db_name doesn't exist it will create it 
 +# However, db_name will not be saved unless you create a collection 
 +db.createCollection("Collection0"
 +</code> 
 + 
 +---- 
 +===== Create user ===== 
 +<code mongodb> 
 +# first user 
 +use admin 
 +> db.createUser( 
 +... { 
 +... user: "kalenpw", 
 +... pwd: passwordPrompt(), 
 +... roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase"
 +... } 
 +... ) 
 + 
 +# user for specific database 
 +use db_name 
 +> db.createUser( 
 +... { 
 +... user: "kalenpw", 
 +... pwd: passwordPrompt(), 
 +... roles: [ 
 +... { role: "readWrite", db: "locallibrary"
 +... ] 
 +... } 
 +... ) 
 + 
 +</code>
  
 ---- ----
Line 26: Line 67:
 db.authors.countDocuments({}) // requires empty filter db.authors.countDocuments({}) // requires empty filter
 </code> </code>
 +----