package mongodb;
import java.util.ArrayList;
import java.util.List;
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.MongoCredential;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
public class MongodbDelete {
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
// 認證
MongoCredential journaldevAuth = MongoCredential.createMongoCRCredential("your username", "your database", "your password".toCharArray());
List auths = new ArrayList();
auths.add(journaldevAuth);
//連線
ServerAddress serverAddress = new ServerAddress("your address", your port);
MongoClient mongo = new MongoClient(serverAddress,auths);
//選擇連線database
DB db = mongo.getDB("your database");
//選擇collection (table)
DBCollection site = db.getCollection("site");
BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("city", "Taipei");
site.remove(searchQuery);
}
catch(UnknownHostException ex)
{
}
}
}
2015-09-16
MongoDB using Java part 2 - delete
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment