Get a Saved Object in MongoDB

AmitDiwan
Updated on 03-Apr-2020 12:21:09

268 Views

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") }

Store Query Output in Temporary MongoDB Database

AmitDiwan
Updated on 03-Apr-2020 12:19:23

761 Views

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

Rebuilding Indexes in MongoDB

AmitDiwan
Updated on 03-Apr-2020 12:18:08

639 Views

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 }

Create Navigation Bar with Equal Width Links using CSS

AmitDiwan
Updated on 03-Apr-2020 10:47:08

1K+ Views

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 −

Create Navigation Bar with Centre Link and Logo using CSS

AmitDiwan
Updated on 03-Apr-2020 10:43:53

420 Views

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−

Read in a File in C# with StreamReader

karthikeya Boyini
Updated on 03-Apr-2020 10:43:20

565 Views

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

StreamWriter in C#

Samual Sam
Updated on 03-Apr-2020 10:37:22

229 Views

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

Read Contents of a File into a String in C#

Samual Sam
Updated on 03-Apr-2020 10:36:03

300 Views

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

Create Horizontal Scrollable Menu with CSS

AmitDiwan
Updated on 03-Apr-2020 09:19:49

720 Views

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 −

Create Hoverable Sidenav with CSS

AmitDiwan
Updated on 03-Apr-2020 09:09:33

396 Views

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

Advertisements