Get Duplicate Values of a Field in MongoDB

Chandu yadav
Updated on 30-Jul-2019 22:30:25

1K+ Views

Use aggregate() method to get the duplicate value of a field. Let us first create a collection with documents using the following query> db.findAllNonDistinctDemo.insertOne({"UserName":"John", "UserAge":28}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995078863d6ffd454bb647") } > db.findAllNonDistinctDemo.insertOne({"UserName":"Larry", "UserAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995081863d6ffd454bb648") } > db.findAllNonDistinctDemo.insertOne({"UserName":"Larry", "UserAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995089863d6ffd454bb649") } > db.findAllNonDistinctDemo.insertOne({"UserName":"David", "UserAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c995093863d6ffd454bb64a") } > db.findAllNonDistinctDemo.insertOne({"UserName":"John", "UserAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c99509d863d6ffd454bb64b") } > db.findAllNonDistinctDemo.insertOne({"UserName":"Robert", "UserAge":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9950a7863d6ffd454bb64c") } ... Read More

Change Primary Key in MySQL to Auto Increment

George John
Updated on 30-Jul-2019 22:30:25

4K+ Views

To change a primary key to auto_increment, you can use MODIFY command. Let us first create a table.mysql> create table changePrimaryKeyInAutoIncrement    -> (    -> StudentId int not null primary key,    -> StudentName varchar(100),    -> StudentAge int,    -> StudentAddress varchar(100)    -> ); Query OK, 0 rows affected (0.63 sec)Let us now check the description of table using desc command:mysql> desc changePrimaryKeyInAutoIncrement;This will produce the following output+----------------+--------------+------+-----+---------+-------+ | Field          | Type         | Null | Key | Default | Extra | +----------------+--------------+------+-----+---------+-------+ | StudentId      | int(11)   ... Read More

Get Number of Quarters Between Two Dates in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

623 Views

Let’s say we have the following two dates −LocalDate.of(2019, 3, 20); LocalDate.of(2019, 10, 25);To get the number of quarters between the above two dates, use the QUARTER_YEARS −IsoFields.QUARTER_YEARS.between(LocalDate.of(2019, 3, 20),LocalDate.of(2019, 10, 25));Exampleimport java.time.LocalDate; import java.time.temporal.IsoFields; public class Demo {    public static void main(String[] args) {       long quarters =          IsoFields.QUARTER_YEARS.between(LocalDate.of(2019, 3, 20), LocalDate.of(2019, 10, 25));       System.out.println("Quarters between the two dates = " + quarters);    } }OutputQuarters between the two dates = 2

Remove Null Element from MongoDB Array

Samual Sam
Updated on 30-Jul-2019 22:30:25

1K+ Views

You can use $pull operator for this. Let us first create a collection with documents −> db.removeNullDemo.insertOne( ... { ...    "_id" : 1, ...    "StudentDetails" : [ ...       { ...          "FirstName": "John", ...          "LastName":"Smith", ... ...       }, ...       { ...          "Age":21 ...       }, ...       null ... ...    ] ... } ... ); { "acknowledged" : true, "insertedId" : 1 } > db.removeNullDemo.insertOne( ... { ...    "_id" : 2, ... ... Read More

Reasons That Could Make Your Training a Flop

Anuradha Nanda
Updated on 30-Jul-2019 22:30:25

185 Views

You have attended a great training session, which was very interactive and all the participants enjoyed the session. Even the trainer was very good, but still, there was not a great outcome from it. What could be the reason?It may be because Service / Customer Satisfaction Scores Are Poor. In other words, you might not have scheduled enough employees to handle responsibilities, like the lunchtime rush, or the cashier stations, or parking during a busy holiday week. There could be many other reasons too:Irrelevant Topics Discussed: We need to evaluate the training properly. Maybe the topic of the training was not ... Read More

Why is the Term Bachelor Used in Educational Qualifications

Suman Nanda
Updated on 30-Jul-2019 22:30:25

297 Views

A college degree (from Middle Asian baccalaureus) or baccalaureate (from Modern Latin baccalaureates) is an undergraduate academic level awarded by universities and colleges after completion of training lasting three to several years (depending on the organization and academic discipline).Origin of the TermThe definition of bachelor in the twelfth century referred to a knight bachelor, who was too young or poor to gather vassals under his own banner. By simply the end of the 13th century, it was also employed by junior associates of guilds or schools. By folk etymology or wordplay, the word baccalaureus was associated with bacca Laurie ("laurel berry")It was ... Read More

Rotation of Stepper Motor in Forward and Reverse Directions

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

3K+ Views

Let us consider ALS-NIFC-01, which is a stepper motor interface. Using 26-core flat cable, it is connected to ALS kit. It will be used for interfacing two stepper motors. In our current experiment, we use only one stepper motor. The motor has a step size of 1.8°. The stepper motor works on a power supply of +12V. Power supply of +5V (white wire), GND (black), and +12V (red) is provided to the interface. Note that -12V supply is not used by the interface. We shall have to make sure that the +12V supply has adequate current rating to drive the ... Read More

Add Multiple Copies in ArrayList for ListView in Android

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

172 Views

This example demonstrates How to add multiple copies in arrylist for Listview in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/ activity_main.xml.                         In the above code, we have taken name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on ... Read More

MySQL Operator for Multiple NOT Conditions

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

544 Views

Yes, for this MySQL comes with a NOT IN.The syntax is as followsSELECT *FROM yourTableName WHERE yourColumnName NOT IN(1, 2, 7);To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table User_informations    - > (    - > UserId int,    - > UserName varchar(20)    - > ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into User_informations values(12, 'Maxwell'); Query OK, 1 row affected (0.17 sec) mysql> insert into User_informations values(7, 'David'); Query OK, 1 ... Read More

What Are Cookies in JSP

Samual Sam
Updated on 30-Jul-2019 22:30:25

324 Views

Cookies are text files stored on the client computer and they are kept for various information tracking purposes. JSP transparently supports HTTP cookies using underlying servlet technology.There are three steps involved in identifying and returning users -Server script sends a set of cookies to the browser. For example, name, age, or identification number, etc.Browser stores this information on the local machine for future use.When the next time the browser sends any request to the web server then it sends those cookies information to the server and server uses that information to identify the user or may be for some other ... Read More

Advertisements