diff --git a/mongo.md b/mongo.md new file mode 100644 index 0000000..7aa7c67 --- /dev/null +++ b/mongo.md @@ -0,0 +1,38 @@ +` show dbs ` list all the databases which is having any collection(table) + +` use ` switched to database with name . If there is no database with given name, creates one and switched to it. + +` db ` outputs the currently used database + +` db.createCollection() ` creates a collection + +` show collections ` list the collections in current selected database + +` db..insert({}) ` inserts the object in collection + +` db..insertMany([{}]) ` inserts the objects in collection + +` db..find() ` lists the object in collection + +` db..find({ key: value }) ` lists the object in collection which matches given key value pair(words(key-value pair) are case sensitive) + +` db..find().pretty() ` lists the objects in collection in more readable format + +` db..find().sort({ key: }) ` lists the objects in collection in sorted form. value{ 1: asc, -1: desc} + +` db..find().count() ` show the count of objects in collection + +` db..find().limit() ` show the list of objects in collection by given quantity + +` db..find().forEach() ` list of objects in collection based on given object + +` db..findOne({}) ` show the first object in collection; condition is optional + +` db..update() ` update the object. +- `.update({}, {}, {upsert: true/false}) ` If the upsert value is true then the new object is created if there is no object with given matching condition otherwise ignores + - ` ` If the object is given directly, then it will override the content of previous object + - ` $set: ` The object will be updated with prevoious values intact + - ` $inc: {key: value} ` the object will be updated with incrementing the value of key by + - ` #rename: { old_key: new_key } ` the old key will be renamed to new key + +` db..remove({}) ` remove the object from collection \ No newline at end of file