Pretty Print in MongoDB Shell as Default

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

247 Views

You can call pretty() function on cursor object to prettyprint in MongoDB shell. The syntax is as follows −db.yourCollectionName.find().pretty();To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −>db.prettyDemo.insertOne({"ClientName":"Larry", "ClientAge":27, "ClientFavoriteCountry":["US", "UK"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a440de01f572ca0ccf5f2") } >db.prettyDemo.insertOne({"ClientName":"Mike", "ClientAge":57, "ClientFavoriteCountry":["AUS", "UK"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8a4420e01f572ca0ccf5f3") }Display all documents from a collection with the help of find() method. The query is as follows −> db.prettyDemo.find();The following is the output −{ "_id" : ObjectId("5c8a440de01f572ca0ccf5f2"), "ClientName" : "Larry", "ClientAge" ... Read More

Match Between Fields in MongoDB Aggregation Framework

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

269 Views

      You can use $cmp operator for this. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.matchBetweenFieldsDemo.insertOne({"FirstValue":40, "SecondValue":70}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c9625259fcd19549980d") } > db.matchBetweenFieldsDemo.insertOne({"FirstValue":20, "SecondValue":5}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c96b5259fcd19549980e") }Display all documents from a collection with the help of find() method. The query is as follows −> db.matchBetweenFieldsDemo.find().pretty();The following is the output −{    "_id" : ObjectId("5c92c9625259fcd19549980d"),    "FirstValue" : 40,    "SecondValue" : 70 } {    "_id" : ... Read More

Set Lower Bound Function in C++ STL

Anvi Jain
Updated on 30-Jul-2019 22:30:25

1K+ Views

Set lower_bound() function in C++ STL returns an iterator pointing to the element in the container which is equivalent to k passed in the parameter. If k is not present in the set container, then the function returns an iterator pointing to the immediate next element which is just greater than k.AlgorithmBegin    Initialize an empty set container s.    Initializing a set container as inetrator.    Insert some elements in s set container.    Call function to find the lower bound value of a given key, which is    passed to iter set container.    Print the lower bound ... Read More

Any and All in Python

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

990 Views

Python provides two built-ins functions for “AND” and “OR” operations are All and Any functions.Python any() functionThe any() function returns True if any item in an iterable are true, otherwise it returns False. However, if the iterable object is empty, the any () function will return False.Syntaxany(iterable)The iterable object can be a list, tuple or dictionary.Example 1>>> mylst = [ False, True, False] >>> x = any(mylst) >>> x TrueOutputOutput is True because the second item is True.Example 2Tuple – check if any item is True>>> #Tuple - check if any item is True >>> mytuple = (0, 1, 0, ... Read More

Standard Android Button with a Different Color

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

433 Views

This example demonstrate about Standard Android Button with a different colorStep 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 button view to show different colors.Step 3 − Add the following code to drawable / background.xml                                                         ... Read More

Minus Seconds and Nanoseconds from Instant in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

268 Views

Let us first set an Instant:Instant now = Instant.ofEpochMilli(184142540078l);Let us now minus seconds from Instant:Instant resSeconds = now.minusSeconds(50);Let us now minus nanoseconds from Instant:Instant resNanoSeconds = now.minusNanos(10000);Exampleimport java.time.Instant; public class Demo {    public static void main(String[] args) {       Instant now = Instant.ofEpochMilli(184142540078l);       System.out.println(now);       Instant resSeconds = now.minusSeconds(50);       System.out.println("After subtracting seconds = "+resSeconds);       Instant resNanoSeconds = now.minusNanos(10000);       System.out.println("After subtracting nanoseconds = "+resNanoSeconds);    } }Output1975-11-02T06:42:20.078Z After subtracting seconds = 1975-11-02T06:41:30.078Z After subtracting nanoseconds = 1975-11-02T06:42:20.077990Z

Find Next Auto Increment Value in MySQL

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

101 Views

Yes, you can find out the next auto_increment with SELECT AUTO_INCREMENT as shown in the below syntax −SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA= yourDatabaseName AND TABLE_NAME=yourTableName;Let us first create a table −mysql> create table DemoTable (    ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ClientName varchar(20),    ClientAge int ); Query OK, 0 rows affected (1.33 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ClientName, ClientAge) values('John', 23); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable(ClientName, ClientAge) values('Carol', 21); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(ClientName, ClientAge) values('Bob', ... Read More

SecureRandom nextBytes Method in Java

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

430 Views

The number of random bytes as specified by the user can be obtained using the nextBytes() method in the class java.security.SecureRandom. This method requires a single parameter i.e. a random byte array and it returns the random bytes as specified by the user.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String s = "Apple";          byte[] arrB = s.getBytes();         ... Read More

Use Singleton Alert Dialog in Android

Nitya Raut
Updated on 30-Jul-2019 22:30:25

530 Views

Before getting into example, we should know what singleton design pattern is.  A singleton is a design pattern that restricts the instantiation of a class to only one instance. Notable uses include controlling concurrency, and creating a central point of access for an application to access its data store.This example demonstrates How to use Singleton Alert Dialog in androidStep 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 ... Read More

Create Aggregate Checksum of a Column in MySQL

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

612 Views

You can use CRC32 checksum for this. The syntax is as follows −SELECT SUM(CRC32(yourColumnName)) AS anyAliasName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CRC32Demo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserId varchar(20)    -> ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into CRC32Demo(UserId) values('USER-1'); Query OK, 1 row affected (0.38 sec) mysql> insert into CRC32Demo(UserId) values('USER-123'); Query OK, 1 row ... Read More

Advertisements