import [Link].
MongoClients;
import [Link];
import [Link];
import [Link];
import [Link];
public class Inserting {
public static void main(String[] args) {
// Creating a Mongo client using MongoClients
// MongoClient mongoClient =
[Link]("mongodb://localhost:27017");
// [Link]("Connected to the database successfully");
// Creating a Mongo client using MongoClients This is ma'am Photo
MongoClient mongo = new MongoClient("localhost",27017);
[Link]("Connected to the database successfully");
// Accessing the database
MongoDatabase database = [Link]("BatchB");
// Accessing the collection
MongoCollection<Document> collection = [Link]("S1");
[Link]("Collection sampleCollection1 selected successfully");
// Creating a document to insert
Document document = new Document();
[Link]("id", 1);
[Link]("description", "AWP");
[Link]("likes", 100);
[Link]("url", "[Link]
[Link]("by", "DOT NET Framework");
[Link]("project_by", "Nutan");
// Inserting the document into the collection
[Link](document);
[Link]("Document inserted successfully");
// Closing the Mongo client connection
[Link]();
}
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Inserting {
public static void main(String[] args) {
// Creating a Mongo client using MongoClients
// MongoClient mongoClient =
[Link]("mongodb://localhost:27017");
// [Link]("Connected to the database successfully");
// Creating a Mongo client using MongoClients This is ma'am Photo
MongoClient mongo = new MongoClient("localhost",27017);
[Link]("Connected to the database successfully");
// Accessing the database
MongoDatabase database = [Link]("BatchB");
// Accessing the collection
MongoCollection<Document> collection = [Link]("S1");
[Link]("Collection sampleCollection1 selected successfully");
// Creating a document to insert
Document document = new Document();
[Link]("id", 1);
[Link]("description", "AWP");
[Link]("likes", 100);
[Link]("url", "[Link]
[Link]("by", "DOT NET Framework");
[Link]("project_by", "Nutan");
// Inserting the document into the collection
[Link](document);
[Link]("Document inserted successfully");
// Closing the Mongo client connection
[Link]();
}
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Reading {
// Creating a Mongo client using MongoClients This is ma'am Photo
MongoClient mongo = new MongoClient("localhost",27017);
[Link]("Connected to the database successfully");
// Accessing the database
MongoDatabase database = [Link]("BatchB");
// Accessing the collection
MongoCollection<Document> collection = [Link]("S1");
[Link]("Collection sampleCollection1 selected successfully");
FindIterable<Document> iterDoc = [Link]();
int i = 1;
Iterator it = [Link]();
while([Link]()) {
[Link]([Link]());
i++;
}
}
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Update {
public static void main(String[] args) {
// Creating a Mongo client
try (MongoClient mongoClient =
[Link]("mongodb://localhost:27017")) {
[Link]("Connected to the database successfully");
// Accessing the database
MongoDatabase database = [Link]("BatchB");
// Accessing the collection
MongoCollection<Document> collection = [Link]("S1");
[Link]("Collection S1 selected successfully");
// Update operation
[Link]([Link]("id", 1), new Document("$set", new
Document("name", "Updated Name")));
[Link]("Document updated successfully...");
}
}
}