Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Chandu yadav
Page 29 of 81
Search a string with special characters in a MongoDB document?
To search a string with special characters in MongoDB document, you can use backslash (\) to escape the special character in a regular expression. Here, we have special character $ in our string. Syntax db.collection.find({ "fieldName": /.*\specialCharacter.*/i }); Sample Data Let us first create a collection with documents ? db.searchDocumentWithSpecialCharactersDemo.insertMany([ { "UserId": "Smith$John123", "UserFirstName": "John", "UserLastName": "Smith" ...
Read MoreGet the array of _id in MongoDB?
In MongoDB, the _id field is a mandatory field that acts as the primary key for each document. To retrieve documents by matching their _id values against an array of specific values, use the $in operator. Syntax db.collectionName.find({ _id: { $in: [value1, value2, value3, ...] } }); Create Sample Data db.selectInWhereIdDemo.insertMany([ {"_id": 23}, {"_id": 28}, {"_id": 45}, {"_id": 75}, {"_id": 85}, {"_id": 145} ]); { ...
Read MoreHTML5 input type="file" accept="image/*" capture="camera" display as image rather than choose file button
Use the JavaScript FileReader to allow users to choose an image file and display it as an image instead of showing the default file input button. This approach provides a better user experience by giving immediate visual feedback when an image is selected. The HTML5 input element with type="file", accept="image/*", and capture="camera" attributes allows users to select images from their device or capture photos directly from the camera on mobile devices. HTML Structure First, let's create the basic HTML structure with a file input and an image element − ...
Read MoreHow to reload the current page without losing any form data with HTML?
The easiest way to reload the current page without losing form data is to use WebStorage, where you have persistent storage (localStorage) or session-based (sessionStorage) which remains in memory until your web browser is closed. Using localStorage to Preserve Form Data The key is to save form data before the page reloads and restore it after the page loads. Here's how to implement this solution − Step 1: Save Form Data Before Page Reload Use the beforeunload event to capture form data when the page is about to reload − window.onbeforeunload = function() { ...
Read MoreFacing Problem in retrieving HTML5 video duration
A common problem when working with HTML5 video is that the duration property returns NaN (Not a Number) when you try to access it before the browser has finished loading the video's metadata. This happens because the video file's metadata (which contains the duration, dimensions, etc.) is not available immediately after the page loads. Why Does video.duration Return NaN? The HTML5 element has a readyState attribute that indicates how much data the browser has loaded. It has values from 0 to 4 − 0 (HAVE_NOTHING) − No data available yet. 1 (HAVE_METADATA) − Metadata (duration, dimensions) is loaded. ...
Read MoreAre new HTML5 elements like and useless?
No, HTML5 semantic elements like and are not useless. They are extremely useful for screen readers and assistive technologies, helping visually impaired users navigate and understand the structure of your web page. They are also beneficial for eBook readers, search engines, and any tool that parses HTML for meaning. While you could use generic tags for everything, semantic elements convey the purpose of the content to both browsers and developers, making your code more readable and accessible. The Element The element represents a thematic grouping of content, typically with a heading. Use it to divide ...
Read MoreJava Program to Check if a String is Numeric
ExampleYou can check if a given string is Numeric as shown in the following program.import java.util.Scanner; public class StringNumeric { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string ::"); String str = sc.next(); boolean number = str.matches("-?\d+(\.\d+)?"); if(number) { System.out.println("Given string is a number"); } else { System.out.println("Given string is not a number"); } } }OutputEnter a string :: 4245 Given string is a number
Read MoreJava program to calculate mode in Java
In statistics math, a mode is a value that occurs the highest numbers of time. For Example, assume a set of values 3, 5, 2, 7, 3. The mode of this value set is 3 as it appears more than any other number.Algorithm1.Take an integer set A of n values. 2.Count the occurrence of each integer value in A. 3.Display the value with the highest occurrence.Examplepublic class Mode { static int mode(int a[], int n) { int maxValue = 0, maxCount = 0, i, j; for (i = 0; i < n; ...
Read MoreIntStream peek() method in Java
The peek() method in the IntStream class in Java returns a stream consisting of the elements of this stream. It additionally performs the provided action on each element as elements are consumed from the resulting stream.The syntax is as followsIntStream peek(IntConsumer action)Here, the parameter action is a non-interfering action to perform on the elements as they are consumed from the stream. The IntConsumer represents an operation that accepts a single int-valued argument and returns no result.The following is an example to implement IntStream peek() method in JavaExampleimport java.util.*; import java.util.stream.IntStream; public class Demo { public static void ...
Read MoreIntStream forEachOrdered() method in Java
The forEachOrdered() method in Java assures that each element is processed in order for streams that have a defined encounter order.The syntax is as followsvoid forEachOrdered(IntConsumer action)Here, the action parameter is a non-interfering action to be performed on the elements.Create an IntStream and add elements to the streamIntStream intStream = IntStream.of(50, 70, 80, 100, 130, 150, 200);Now, use the forEachOrdered() method to display the stream elements in orderintStream.forEachOrdered(System.out::println);The following is an example to implement IntStream forEachOrdered() method in JavaExampleimport java.util.*; import java.util.stream.IntStream; public class Demo { public static void main(String[] args) { ...
Read More