Let us first create a variable. Following is the query −> var studentDetails={"StudentFirstName":"Chris","StudentLastName":"Brown","StudentAge":24};Following is the query to save records using save() −> db.demo45.save(studentDetails); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> studentDetails;This will produce the following output −{ "StudentFirstName" : "Chris", "StudentLastName" : "Brown", "StudentAge" : 24, "_id" : ObjectId("5e25dab4cfb11e5c34d898ec") }
For this, in a single query, simply work with forEach() and store output in a temp db. Let us first create a collection with documents −> db.demo43.insertOne({"StudentName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e25d4b3cfb11e5c34d898e5") } > db.demo43.insertOne({"StudentName":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e25d4b8cfb11e5c34d898e6") } > db.demo43.insertOne({"StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e25d4bbcfb11e5c34d898e7") }Display all documents from a collection with the help of find() method −> db.demo43.find();This will produce the following output −{ "_id" : ObjectId("5e25d4b3cfb11e5c34d898e5"), "StudentName" : "Chris" } { "_id" : ObjectId("5e25d4b8cfb11e5c34d898e6"), "StudentName" : "Bob" } { "_id" : ObjectId("5e25d4bbcfb11e5c34d898e7"), "StudentName" ... Read More
To rebuild indexes, use reIndex(). Let us first create an index. Following is the query −> db.demo42.createIndex({"StudentFirstName":1});This will produce the following output −{ "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }Following is the query to rebuild index in MongoDB −> db.demo42.reIndex({"StudentFirstName":1});This will produce the following output −{ "nIndexesWas" : 2, "nIndexes" : 2, "indexes" : [ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "web.demo42" }, { "v" : 2, "key" : { "StudentFirstName" : 1 }, "name" : "StudentFirstName_1", "ns" : "web.demo42" } ], "ok" : 1 }
Following is the code to create a navigation bar with equal-width navigation links.−Example Live Demo Document body{ margin:0px; margin-top:60px; padding: 0px; } *,*::before,*::after{ box-sizing: border-box; } nav{ position: fixed; top: 0; width: 100%; background-color: rgb(39, 39, 39); overflow: auto; height: auto; } .links { width: 20vw; padding: 17px; display: inline-block; text-align: center; color: rgb(178, 137, 253); text-decoration: none; font-size: 17px; } .links:hover { background-color: rgb(100, 100, 100); } .selected{ background-color: rgb(0, 18, 43); } Home Login Register Contact Us More Info Equal width navigation menu OutputThe above code will produce the following output −
Following is the code to produce a navigation bar with a centered link/logo −Example Live Demo Document body{ margin:0px; margin-top:60px; padding: 0px; } nav{ position: fixed; top:0; width: 100%; background-color: rgb(251, 255, 196); overflow: auto; height: auto; } .left-links{ display: inline-block; position: absolute; left: 0; } .right-links{ display: inline-block; position: absolute; right: 0; } .center-links{ display: inline-block; margin-left: 50%; } .links { display: inline-block; text-align: center; padding: 14px; color: rgb(0, 0, 0); text-decoration: none; font-size: 17px; font-weight: bolder; } .links:hover { border-bottom: 2px solid purple; } .selected{ border-bottom: 2px solid purple; } Login Register Home Contact Us More Info Hover on the above links OutputThe above code will produce the following output−
To read text files, use StreamReader class in C#.Add the name of the file you want to read −StreamReader sr = new StreamReader("hello.txt");Use the ReadLine() method and get the content of the file in a string −using (StreamReader sr = new StreamReader("hello.txt")) { str = sr.ReadLine(); } Console.WriteLine(str);Let us see the following code −Example Live Demousing System.IO; using System; public class Program { public static void Main() { string str; using (StreamWriter sw = new StreamWriter("hello.txt")) { sw.WriteLine("Hello"); sw.WriteLine("World"); } ... Read More
Write characters to a stream with StreamWriter in C#.With StreamWriter, create a new file −StreamWriter sw = new StreamWriter("hello.txt"))Add text to the file −sw.WriteLine("Hello"); sw.WriteLine("World");The following is the code −Exampleusing System.IO; public class Program { public static void Main() { using (StreamWriter sw = new StreamWriter("hello.txt")) { sw.WriteLine("Hello"); sw.WriteLine("World"); } } }It creates the file “hello.text” and adds text to it −OutputThe following is the output.Hello World
Use ReadToEnd() method to read the contents of a file in a string.Set it under StreamReader and read the file −using (StreamReader sr = new StreamReader("new.txt")){ string res = sr.ReadToEnd(); Console.WriteLine(res); }The following is the complete code −Example Live Demousing System.IO; using System; public class Demo { public static void Main() { using (StreamWriter sw = new StreamWriter("new.txt")) { sw.WriteLine("One"); sw.WriteLine("Two"); } using (StreamReader sr = new StreamReader("new.txt")) { string res = sr.ReadToEnd(); ... Read More
Following is the code to produce a horizontal scrollable menu with CSS −Example Live Demo Document body{ margin:0px; margin-top:10px; padding: 0px; } nav{ width: 100%; background-color: rgb(39, 39, 39); overflow: auto; height: auto; white-space: nowrap; } .links { display: inline-block; text-align: center; padding: 14px; color: rgb(178, 137, 253); text-decoration: none; font-size: 17px; } .links:hover { background-color: rgb(100, 100, 100); } .selected{ background-color: rgb(0, 18, 43); } Home Login Register Contact Us More Info Our Social Links Visit Us OutputThe above code will produce the following output −On resizing the browser window horizontal scrolling will be seen −
Following is the code to create hoverable side navigation buttons with CSS.Example Live Demo Document nav a { position: fixed; left: -120px; transition: 0.3s; padding: 10px; width: 140px; text-decoration: none; font-size: 20px; color: black; font-weight: bolder; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } nav a:hover { left: 0; } #Info{ top: 20px; background-color: #6de2f7; } #Social{ top: 80px; background-color: #71fc71; } #Address { top: 140px; background-color: #c4f553; } #Home { top: 200px; background-color: rgb(225, 115, 240); ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP