Draw Geometrical Shapes on Image Using OpenCV Java Library

Maruthi Krishna
Updated on 10-Apr-2020 07:44:11

507 Views

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc this class provies various methods such as, resize(), wrapAffine(), filter2D, to process an input image.In addition to them It provides a set of method to draw geometrical shapes on images, Following are some of them −ShapeMethod and DescriptionEllipseYou can draw an ellipse on an image using the ellipse() method.CircleYou can draw a circle on an image using the circle() method.RectangleYou can draw a rectangle on an image using the rectangle() method.PolygonYou can draw a polygon on an image using the polygon() method.LineYou can draw a line on an ... Read More

Update Multiple Documents in a MongoDB Collection Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:38:53

2K+ Views

Using the updateMany() method you can update all the documents of a collection.Syntaxdb.COLLECTION_NAME.update(, )In Java the com.mongodb.client.MongoCollection interface provides you a method with the same name. Using this method you can update multiple documents in a collection at once, to this method you need to pass the filter and values for the update.Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; import com.mongodb.client.model.Updates; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import org.bson.conversions.Bson; import com.mongodb.MongoClient; public class UpdatingMultipleDocuments {    public static void main( String args[] ) {       // Creating a Mongo client       MongoClient mongo ... Read More

Update Existing Document in MongoDB Collection using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:36:22

4K+ Views

The update() method updates the values in the existing document.Syntaxdb.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA)In Java, you can update a single document using the updateOne()method of the com.mongodb.client.MongoCollection interface. To this method, you need to pass the filter and values for the update.Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; import com.mongodb.client.model.Updates; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import com.mongodb.MongoClient; public class UpdatingDocuments {    public static void main( String args[] ) {       // Creating a Mongo client       MongoClient mongo = new MongoClient( "localhost" , 27017 );       //Connecting to the database     ... Read More

Sort Documents of a MongoDB Collection Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:34:15

2K+ Views

While retrieving records from a MongoDB collection, you can sort the records in the result using the sort() method.Syntaxdb.COLLECTION_NAME.find().sort({KEY:1})The Java MongoDB library provides a method with the same name, to limit the number of records invoke this method (on the result of the find() method) by passing the type of the sort (ascending or descending) and the field name based on which you want to sort the records as −sort(Sorts.ascending("age");Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Sorts; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import com.mongodb.MongoClient; public class SortingRecords {    public static void main( String args[] ) { ... Read More

Create a Database in MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:32:09

2K+ Views

There is no separate method to create a MongoDB database in Java, you can create a database by invoking the getDatabase() method of the com.mongodb.MongoClient class.Exampleimport com.mongodb.MongoClient; public class CreatingDatabase {    public static void main( String args[] ) {       //Creating a MongoDB client       @SuppressWarnings("resource")       MongoClient mongo = new MongoClient( "localhost" , 27017 );       //Accessing the database       mongo.getDatabase("myDatabase1");       mongo.getDatabase("myDatabase2");       mongo.getDatabase("myDatabase3");       System.out.println("Databases created successfully");    } }OutputDatabases created successfully

Create an Index in MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:30:52

2K+ Views

In MongoDB to create an index, you need to use createIndex() method.Syntaxdb.COLLECTION_NAME.createIndex({KEY:1})Where the key is the name of the file on which you want to create index and 1 is for ascending order. To create an index in descending order you need to use -1.In Java, you can create an Index using the createIndex() method, to this method you need to pass the type of the index (ascending or descending) and the field name on which you want to create the index, as −createIndex(Indexes.descinding("name"));Exampleimport com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Indexes; import org.bson.Document; import com.mongodb.MongoClient; public class CreatingIndex {    public static void ... Read More

Delete Multiple Documents from a Collection in Java

Maruthi Krishna
Updated on 10-Apr-2020 07:28:59

990 Views

In Java the com.mongodb.client.MongoCollection interface provides a method deleteMany(). Using this method you can delete multiple documents from a collection at once, to this method you need to pass the filter specifying the deletion criteria.Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import org.bson.conversions.Bson; import com.mongodb.MongoClient; public class DeletingMultipleDocuments {    public static void main( String args[] ) {       //Creating a MongoDB client       MongoClient mongo = new MongoClient( "localhost" , 27017 );       //Connecting to the database       MongoDatabase database = mongo.getDatabase("myDatabase");     ... Read More

Drop Database in MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:25:59

707 Views

MongoDB db.dropDatabase() command is used to drop a existing database.This will delete the current database. if you haven't selected any, the default (test) database will be deleted.Syntaxdb.dropDatabase()In Java to delete a database, first of all, get the object of the required database using the getDatabase() method and delete it by invokimg the drop() method on it.Exampleimport com.mongodb.MongoClient; import com.mongodb.client.MongoDatabase; public class DropingDatabase {    public static void main( String args[] ) {       //Creating a MongoDB client       @SuppressWarnings("resource")       MongoClient mongo = new MongoClient( "localhost" , 27017 );       //Creating a ... Read More

Drop an Index in MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:24:24

619 Views

In MongoDB to drop an index, you need to use dropIndex() method.Syntaxdb.COLLECTION_NAME.dropIndex({KEY:1})In Java, you can drop an Index using the dropIndex() method, to this method you need to pass the type of the index (ascending or descending) and the field name on which you have created it.dropIndex(Indexes.ascending("name"));Exampleimport com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Indexes; import org.bson.Document; import com.mongodb.MongoClient; public class DroppingIndex {    public static void main( String args[] ) {       //Creating a MongoDB client       MongoClient mongo = new MongoClient( "localhost" , 27017 );       //Accessing the database       MongoDatabase database = ... Read More

Limit Number of Records While Retrieving Data from MongoDB Collection in Java

Maruthi Krishna
Updated on 10-Apr-2020 07:21:52

633 Views

While retrieving records from a MongoDB collection, you can limit the number of records in the result using thelimit() method.Syntaxdb.COLLECTION_NAME.find().limit(no.of records needed)The Java MongoDB library provides a method with the same name, to limit the number of records invoke this method (on the result of the find() method) by passing an integer value representing the required number of records.Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import com.mongodb.MongoClient; public class LimitingRecords {    public static void main( String args[] ) {       //Creating a MongoDB client       MongoClient mongo = ... Read More

Advertisements