Use Type in MongoDB

AmitDiwan
Updated on 12-May-2020 06:41:09

132 Views

The $type selects documents where the value of the field is an instance of the specified BSON type. Let us create a collection with documents −> db.demo615.insert({"Value":100}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":"100"}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":"300"}); WriteResult({ "nInserted" : 1 }) > db.demo615.insert({"Value":300}); WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method −> db.demo615.find();This will produce the following output −{ "_id" : ObjectId("5e99bb3465492f6c60d0027f"), "Value" : 100 } { "_id" : ObjectId("5e99bb3865492f6c60d00280"), "Value" : "100" } { "_id" : ObjectId("5e99bb3c65492f6c60d00281"), "Value" : "300" } { "_id" : ObjectId("5e99bb4265492f6c60d00282"), "Value" ... Read More

What is Natural 1 in MongoDB

AmitDiwan
Updated on 12-May-2020 06:40:05

1K+ Views

The ({$natural − 1}) works like LIFO(LAST IN FIRST OUT), that means last inserted document will be shown first.Let us create a collection with documents −> db.demo614.insertOne({"CountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e988cddf6b89257f5584d8e") } > db.demo614.insertOne({"CountryName":"UK"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e988ce0f6b89257f5584d8f") } > db.demo614.insertOne({"CountryName":"AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e988ce3f6b89257f5584d90") } > db.demo614.insertOne({"CountryName":"IND"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5e988cebf6b89257f5584d91") }Display all documents from a collection with the help of find() method −> db.demo614.find();This will produce the following output −{ "_id" : ObjectId("5e988cddf6b89257f5584d8e"), "CountryName" : "US" } { ... Read More

JavaScript Importing and Exporting Modules

AmitDiwan
Updated on 12-May-2020 06:24:44

305 Views

To import and export modules using JavaScript, the code is as follows −Note − To run this example you will need to run a localhost server.INDEX.htmlExample Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;    } JavaScript Importing and Exporting Modules IMPORT Click on the above button to import module script.jsimport test from './sample.js'; document.querySelector('.Btn').addEventListener('click',()=>{    test(); })sample.jslet resultEle = document.querySelector(".result"); export default function testImport(){    resultEle.innerHTML = 'Module testImport has been imported'; }OutputOn clicking the ‘IMPORT’ button −

Generate Random Hex Codes of Color in JavaScript

AmitDiwan
Updated on 12-May-2020 06:19:40

281 Views

To generate random hex codes of color using JavaScript, the code is as follows −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       box-sizing: border-box;       font-size: 18px;       font-weight: 500;       color: white;       width: 150px;       height: 150px;       text-align: center;       padding-top: 4%;    } Generate random hex codes of color GENERATE Click on the above button to generate a random hex color code    let resultEle = document.querySelector(".result");    let hexCode = "0123456789ABCDEF";    let Color = "#";    document.querySelector(".Btn").addEventListener("click", () => {       for (let i = 0; i < 6; i++)          Color += hexCode[Math.floor(Math.random() * 16)];       resultEle.style.backgroundColor = Color;       resultEle.innerHTML = Color;    }); OutputOn clicking the ‘GENERATE’ button −

JavaScript File Name Property

AmitDiwan
Updated on 12-May-2020 06:16:53

102 Views

The JavaScript File WebAPI file.name property returns only the name of the file without the path.Following is the code for the File WebApi File.name property −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: red;    } JavaScript file.name property Upload a file using the above input type to get its file name    let resultEle = document.querySelector(".result");    document    .querySelector(".fileInput")    .addEventListener("change", (event) => {       resultEle.innerHTML += "File name = " + event.target.files[0].name;    }); OutputOn clicking the ‘Choose file’ button and selecting a file −

JavaScript WeakSet

AmitDiwan
Updated on 12-May-2020 06:14:25

100 Views

The JavaScript WeakSet is used for storing collection of objects. Like set it doesn’t store duplicates.Methods of WeakSet −MethodDescriptionadd(obj)Append new value to the weakSet.delete(obj)Deletes the value from weakSet.has(obj)Returns true or false depending upon if the weakSet object contains the value or not.length()Returns the weakSet object lengthFollowing is the code for the WeakSet in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: red;    } ... Read More

JavaScript unescape() Function with Example

AmitDiwan
Updated on 12-May-2020 06:11:52

253 Views

The JavaScript unescape() function is used to decode an encoded string. It is deprecated in JavaScript version 1.5.Following is the code for the unescape() function −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample,    .result {       font-size: 18px;       font-weight: 500;       color: red;    }    .result {       color: blueviolet;    } JavaScript unescape() property CLICK HERE CLICK the above button to decode the above url ... Read More

JavaScript Undefined Property

AmitDiwan
Updated on 12-May-2020 06:09:36

184 Views

The JavaScript undefined property specifies if a variable has been declared or assigned a value yet.Following is the code for the JavaScript undefined property −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } JavaScript undefined property CLICK HERE CLICK the above button to know if variable age has been defined or not    let sampleEle = document.querySelector(".sample");    let ... Read More

Understanding 'this' Identifier in JavaScript

AmitDiwan
Updated on 12-May-2020 06:04:05

205 Views

The JavaScript this keyword refernces the object to which it belongs. It can refer to the global object if alone or inside a function. It refers to the owner object if inside a method and refers to the HTML element that received the event in an event listener.Following is the code for the JavaScript this Identifier −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } ... Read More

JavaScript Source Property

AmitDiwan
Updated on 12-May-2020 05:52:30

159 Views

The JavaScript source property returns the regexp text against which a given pattern is to matched.Following is the code for the source property −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample,    .result {       font-size: 18px;       font-weight: 500;       color: red;    }    .result {       color: rebeccapurple;    } JavaScript source property The king bought a ring CLICK HERE Click on the above button to get the regex source text    let resultEle = document.querySelector(".result");    let pattern = /ing/gi;    document.querySelector(".Btn").addEventListener("click", () => {       resultEle.innerHTML = "Regexp text = " + pattern.source;    }); OutputOn clicking the ‘CLICK HERE’ button −

Advertisements