NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


use dbname;
show dbs;
db.createCollection('stud');
db.stud.insertMany([{"name":"demo"},{"name":"temp"}]);
db.stud.find().pretty();
db.stud.find({},{"name":1,"_id":0});
db.stud.distinct("city"); //unique cities
db.stud.find({"city":"surat"},{}); //get all the details of who city is surat.
db.stud.find().sort({"enro":-1}) //ascending order
db.stud.find().limit(5) //first five data
db.stud.find().skip(db.stud.count()-3) //last three data
db.stud.update({"name":"demo"},{$set:{"dob":"06/01/1922"}}); //set
db.stud.update({"name":"demo"},{$unset:{"dob":"06/01/1922"}}); //unset
db.stud.find( { $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] } ) //or ,and,lt,gt,eq,lte,gte
db.stud.remove({"city":"vapi"})//remove details who city is vapi
db.stud.find({"name":{$regex:"^.a"}},{_id:0}) //second letter is 'a'
db.stud.count() //count number of data
db.stud.distinct("city").length //total number of city
db.stud.updateMany({},{$inc:{"marks":10}});
db.stud.updateMany({},{$mul:{"price":1.5}});
db.stud.aggregate({$group:{_id:0,min:{$min:'$marks'},max:{$max:'$marks'}}});
db.stud.aggregate({$group:{_id:0,avg_marks:{$avg:'$marks'}}});
db.Items.aggregate({$project:{_id:0,msg:{$concat:["$name","price is ",{ $toString: "$price" }]}}})//display msg custome
db.Items.aggregate({$project:{_id:0,msg:{$concat:["The","$name"," stock date is ",stockdate:{$dateToString: { format: "%Y-%m-%d", date: "$stockdate"}}]}}})
---------
Array
---------
db.emp_count.insertOne({"emp_name":"ABC", "emp_skills": [["PostgreSQL", "MongoDB", "MySQL", "Perl","ORACLE"]]});
db.stud_test.find ({results: {$all: [88]}}) //display all the filed form array
db.stud_test.find({results: {$elemMatch: {$gte: 80, $lt: 95}}}) //only match given critria
db.stud_test.find ({“results": {$size: 3}}); //three recoreds show
db.stud_test.updateOne ({stud_id: 1, results: 85},{$set: {"results.$" : 95 }}) // identify array element and update the same into the collection
db.stud_test.updateOne( { stud_id: 1 }, { $pop: { results: -1 } } ) //remove the first and last element from an array
db.stud_test.update( { stud_id: 1 }, { $pull: { results: { $gte: 95 } } } ) // is used to remove elements from an existing array.
db.stud_test.update ({stud_id: 1}, { $push: { results: 101 }}) //push the element
---------
import and export
---------
sudo mongoimport --db newdb --collection restaurants --file primer-dataset.json
sudo mongoexport --db newdb -c restaurants --out newdbexport.json

--or-- run both import and export outside mongo shell
mongimport --db<dbname> --collection<cname> --file filename.json
-> mongoimport --jsonArray --db newDB --collection stud --file /stud.json

mongoexport
mongoexport --db<dbname> --collection<cname> --file filename.json
-> mongoexport --db mydb --collection emp --type=CSV --fields name,age,salary --out
---------
mapReduce
---------
var map=function(){ emit(this.age,this.rank)};
var reduce=function(age,rank){ return Array.sum(rank);}; //Array.avg(rank)
db.employee.mapReduce(map,reduce,{out :"resultCollection1"});
db.resultCollection1.find()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.