Skip to content

Instantly share code, notes, and snippets.

1. Write a MongoDB query to display all the documents in the collection restaurants.
db.restaurants.find().pretty()
or
db.restaurants.find()
2. Write a MongoDB query to display the fields restaurant_id, name, borough and cuisine for all the documents in the collection restaurant
db.restaurants.find({}, {"restaurant_id":1, "name":1,"borough":1 , "cuisine":1})
3. Write a MongoDB query to display the fields restaurant_id, name, borough and cuisine, but exclude the field _id for all the documents in the collection restaurant.
db.restaurants.find({}, {"restaurant_id":1, "name":1,"borough":1 , "cuisine":1, "_id":0})
Step 1 : Create abstract and concrete classes
//abstract class Pizza
public abstract class Pizza {
public abstract void bakePizza();
}
//CheesePizza subclass
public class CheesePizza extends Pizza {
class Person {
private final String firstName; // required
private final int age;
private final String phone;
private Person(PersonBuilder builder) {
this.firstName = builder.firstName;
this.age = builder.age;
this.phone = builder.phone;
public interface PaymentStrategy {
public void pay(int amount);
}
public class CreditCardStrategy implements PaymentStrategy {
private String name;
private String cardNumber;
interface DatabaseExecuter {
public void executeDatabase(String query);
}
class DatabaseExecuterImpl implements DatabaseExecuter {
@Override
public void executeDatabase(String query) {
System.out.println("Going to execute Query: " + query);
}
class Singleton {
//static field
private static Singleton object;
//private Construtor
private Singleton() {}
//static method
public static synchronized Singleton getInstance()
public class Triangle implements Polygon {
@Override
public void calculateArea() {
// TODO
}
}
public class Rectangle implements Polygon {
@Override
public void calculateArea() {
// TODO
}
}
public class Square implements Polygon {
@Override
public void calculateArea()
{
// TODO
}
}
interface Polygon {
void calculateArea();
}