aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2019-02-20 11:42:39 +0100
committerneodarz <neodarz@neodarz.net>2019-02-20 11:42:39 +0100
commitad60fc5e68ead19c45e960a156fbc48f9371dc4e (patch)
tree9a83ec8cf80bef12036c98033309a4184a80dcf2
parentc57807815e7b2183b766d5f2b52222c30a116475 (diff)
downloaddotfiles_ascii-ad60fc5e68ead19c45e960a156fbc48f9371dc4e.tar.xz
dotfiles_ascii-ad60fc5e68ead19c45e960a156fbc48f9371dc4e.zip
Add mongodb tips
-rw-r--r--cheat/.cheat/mongodb28
1 files changed, 28 insertions, 0 deletions
diff --git a/cheat/.cheat/mongodb b/cheat/.cheat/mongodb
new file mode 100644
index 0000000..54b8652
--- /dev/null
+++ b/cheat/.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");
+ }
+ }
+ }
+};