Distinct Aggregation of an Array Field Across Indexes

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

128 Views

To get a distinct aggregation of an array field across indexes, let us take an example and create a collection with some documents.Following is the query to create a collection with documents> db.distinctAggregation.insertOne({"UserName":"Larry", "UserPost":["Hi", "Hello"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c98aefb330fd0aa0d2fe4c6") } > db.distinctAggregation.insertOne({"UserName":"Chris", "UserPost":["Hi", "Good Morning"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c98af0a330fd0aa0d2fe4c7") } > db.distinctAggregation.insertOne({"UserName":"Robert", "UserPost":["Awesome"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c98af1e330fd0aa0d2fe4c8") }Following is the query to display all documents from a collection with the help of find() method> db.distinctAggregation.find().pretty();This will produce the following output{    "_id" : ObjectId("5c98aefb330fd0aa0d2fe4c6"),   ... Read More

Dynamically Change TableView Cell Height in Swift

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

7K+ Views

To change the height of tableView cell in ios dynamically, i.e resizing the cell according to the content available, we’ll need to make use of automatic dimension property. We’ll see this with the help of an sample project.Create an empty project and go to it’s viewController class, conform it to UITableViewDataSource and UITableViewDelegate.Now, In the below code, we will first create a table, then register a cell for that table, and add some table properties.We’ll set the table view delegate and table view datasource.Finally we’ll add the table view to view. Then we’ll call this function inside the viewDidLoad method ... Read More

Convert Java Util Date to Java Time LocalDateTime

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

187 Views

First, set the date −java.util.Date date = new Date();Now, convert the above Date to java.time.LocalDateTime −java.time.LocalDateTime dateTime =    java.time.LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());Exampleimport java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       java.util.Date date = new Date();       System.out.println("Date = "+date);       java.time.LocalDateTime dateTime =          java.time.LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());       System.out.println("LocalDateTime = "+dateTime);    } }OutputDate = Thu Apr 18 23:39:34 IST 2019 LocalDateTime = 2019-04-18T23:39:34.400

Convert ISODate to Numerical Value in MongoDB

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

465 Views

You can use getTime() for this. Following is the syntax −yourVariableName.getTime();Convert ISODate to numerical value −> var arrivalDate=ISODate('2019-04-18 13:50:45');Following is the query to convert ISODate to numerical value −> arrivalDate.getTime();This will produce the following output −1555595445000 Let us verify that it is a correct numerical value for ISODate or not. Following is the query to get correct ISODate whenever we apply above numeric value −> new Date(1555595445000);This will produce the following output −ISODate("2019-04-18T13:50:45Z")Yes, this is a correct ISODate.

Correctly Enclose Subquery in MySQL

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

275 Views

You need to close the subquery in a parenthesis. The syntax is as follows −select if((select count(*) from yourTableName ), 'Yes', 'No') as anyAliasName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table SelectIfDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(10) -> ); Query OK, 0 rows affected (1.03 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into SelectIfDemo(Name) values('John'); Query OK, ... Read More

Java 8 Clock getZone Method

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

181 Views

The time zone required for the date and time creation can be obtained using the method getZone() in the Clock Class in Java. This method requires no parameters and it returns the required time zone.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Clock c = Clock.systemDefaultZone();     ZoneId z = c.getZone(); System.out.println("The clock is: " + c); System.out.println("The ZoneId is: " + z); } ... Read More

AddAtX Method for Pair Class in Java Tuples

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

93 Views

The addAtX() method is used to add value at a particular position represented by X here.Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Here we have also used the Triplet class, therefore import the following package −import org.javatuples.Triplet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an ... Read More

Change MySQL Column Datatype from TEXT to TIMESTAMP

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

3K+ Views

To change a MySQL column datatype from text to timestamp, you need to use ALTER command.The syntax is as followsALTER TABLE yourTableName MODIFY COLUMN yourColumnName TIMESTAMP;To understand the above syntax, let us create a table.The query to create a table is as followsmysql> create table textTotimestampdemo    - > (    - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > Source text    - > ); Query OK, 0 rows affected (0.44 sec)Here is the description of table using DESC command.The syntax is as followsDESC yourTableName;The query is as followsmysql> desc textTotimestampdemo;The following is the output+--------+---------+------+-----+---------+----------------+ | ... Read More

Uploaded Files Storage Location in JSP

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

499 Views

A JSP can be used with an HTML form tag to allow users to upload files to the server. An uploaded file can be a text file or a binary or an image file or just any document.Creating a File Upload FormLet us now understand how to create a file upload form. The following HTML code creates an uploader form. Following are the important points to be noted down −The form method attribute should be set to POST method and the GET method cannot be used.The form enctype attribute should be set to multipart/form-data.The form action attribute should be set ... Read More

LongStream forEach Method in Java

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

182 Views

The forEach() method of the LongStream class in Java performs an action for each element of this stream.The syntax is as followsvoid forEach(LongConsumer action)Here, the parameter action is a non-interfering action to perform on the elements. LongConsumer represents an operation that accepts a single long-valued argument and returns no result.To use the LongStream class in Java, import the following packageimport java.util.stream.LongStream;The following is an example to implement LongStream forEach() method in JavaExample Live Demoimport java.util.*; import java.util.stream.LongStream; public class Demo { public static void main(String[] args) { LongStream longStream = LongStream.of(1000L, 12000L, ... Read More

Advertisements