============ Aggregation & JAVA Program In MongoDB ============
import java.net.UnknownHostException;
import java.util.regex.Pattern;
import com.mongodb.*;
public class ManagePeople {
public static void main(String[] args) {
try {
Mongo m = new Mongo("localhost", 27017);
DB db = m.getDB("sampledb");
DBCollection coll = db.getCollection("people");
DBCursor cur = coll.find();
while (cur.hasNext())
coll.remove(cur.next());
coll.ensureIndex(new BasicDBObject("id",