aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/cheat/mongodb
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-09-05 07:05:07 +0200
committerneodarz <neodarz@neodarz.net>2019-09-05 07:05:07 +0200
commite0c0d4b38cde20e2300e86b69414dd9851b47456 (patch)
tree5df65243447352a9637d1f783247bfd5ccff2ef4 /dotfiles/cheat/mongodb
parentdc45bf89a66ec6c8cd25cf5605deb853f6984705 (diff)
downloaddotfiles_dotdrop-e0c0d4b38cde20e2300e86b69414dd9851b47456.tar.xz
dotfiles_dotdrop-e0c0d4b38cde20e2300e86b69414dd9851b47456.zip
ooo
Diffstat (limited to 'dotfiles/cheat/mongodb')
-rw-r--r--dotfiles/cheat/mongodb28
1 files changed, 28 insertions, 0 deletions
diff --git a/dotfiles/cheat/mongodb b/dotfiles/cheat/mongodb
new file mode 100644
index 0000000..54b8652
--- /dev/null
+++ b/dotfiles/cheat/mongodb
@@ -0,0 +1,28 @@
+# Create user, don't forget to use the correct database
+use <db_name>
+db.createUser({user:"root", pwd:"root", roles: ["readWrite"]})
+
+# Create use in another database:
+db.createUser({user:"admin", pwd:"vIhVPwy81sdf5fPt3a2", roles: [{role: "readWrite" , db: "madbtest"}]})
+
+# mongoshell get schema collection
+# Source: https://medium.com/@ahsan.ayaz/how-to-find-schema-of-a-collection-in-mongodb-d9a91839d992
+
+function printSchema(obj, indent) {
+ for (var key in obj) {
+ if(typeof obj[key] != "function"){ //we don't want to print functions
+ var specificDataTypes=[Date,Array]; //specify the specific data types you want to check
+ var type = typeof obj[key];
+ for(var i in specificDataTypes){ // looping over [Date,Array]
+ if(obj[key] instanceof specificDataTypes[i]){ //if the current property is instance of the DataType
+ type = specificDataTypes[i].name; //get its name
+ break;
+ }
+ }
+ print(indent, key, type) ; //print to console (e.g roles object is_Array)
+ if (typeof obj[key] == "object") { //if current property is of object type, print its sub properties too
+ printSchema(obj[key], indent + "\t");
+ }
+ }
+ }
+};