com.mongodb.DBCollection#drop ( )源码实例Demo

下面列出了com.mongodb.DBCollection#drop ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@RequestMapping(method = RequestMethod.GET)
public @ResponseBody Result onRootAccess() {

    DBCollection collection = mongoTemplate.getCollection("test");
    long count = collection.getCount();
    log.info("Object count in 'test' collection before insert: " + count + "<br/> Inserting one object.<br/>");

    BasicDBObject dBObject = new BasicDBObject();
    dBObject.put("hello", "world");
    collection.insert(dBObject);
    count = collection.count();
    log.info("Object count in test collection after insert:" + count);

    Result result = new Result();
    List<DBObject> dbObjects = new ArrayList<DBObject>();
    DBCursor cursor = collection.find();
    while (cursor.hasNext()) {
        com.mongodb.DBObject obj = cursor.next();
        final String value = (String) obj.get("hello");
        DBObject object = new DBObject();
        object.setKey("hello");
        object.setValue(value);
        dbObjects.add(object);
    }
    result.setDbObjects(dbObjects);
    result.setStatus(
            "Successfully accessed Mongodb service. Retrieving the data object inserted in test collection.");
    collection.drop();
    return result;
}
 
源代码2 项目: gameserver   文件: MongoUtil.java
/**
 * Drop the given collection from database.
 * @param databaseName
 * @param namespace
 * @param collection
 */
public static final void dropCollection(String databaseName,
		String namespace, String collection ) {
	
	DBCollection coll = getDBCollection(databaseName, namespace, collection);
	coll.drop();
}
 
源代码3 项目: gameserver   文件: MongoDBUtil.java
/**
 * Drop the given collection from database.
 * @param databaseName
 * @param namespace
 * @param collection
 */
public static final void dropCollection(String databaseName,
		String namespace, String collection ) {
	
	DBCollection coll = getDBCollection(databaseName, namespace, collection);
	coll.drop();
}
 
@Override
public boolean removeQueue(String jobClientNodeGroup) {
    String tableName = JobQueueUtils.getFeedbackQueueName(jobClientNodeGroup);
    DBCollection dbCollection = template.getCollection(tableName);
    dbCollection.drop();
    LOGGER.info("drop queue " + tableName);
    return true;
}
 
@Override
public boolean removeQueue(String taskTrackerNodeGroup) {
    String tableName = JobQueueUtils.getExecutableQueueName(taskTrackerNodeGroup);
    DBCollection dbCollection = template.getCollection(tableName);
    dbCollection.drop();
    LOGGER.info("drop queue " + tableName);

    return true;
}