Example usage for com.mongodb BasicDBObject getObjectId

List of usage examples for com.mongodb BasicDBObject getObjectId

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject getObjectId.

Prototype

public ObjectId getObjectId(final String field, final ObjectId def) 

Source Link

Document

Returns the object id or def if not set.

Usage

From source file:com.ikanow.infinit.e.processing.generic.GenericProcessingController.java

License:Open Source License

static ObjectId getRootCommunity(ObjectId parentCommunityId) {

    for (;;) {/*  w  w w . j a v  a 2  s  .  co m*/
        BasicDBObject query = new BasicDBObject("_id", parentCommunityId);
        BasicDBObject field = new BasicDBObject("parentId", 1);
        BasicDBObject retVal = (BasicDBObject) MongoDbManager.getSocial().getCommunity().findOne(query, field);
        if (null == retVal) { // (shouldn't ever happen)
            return parentCommunityId;
        }
        ObjectId tmp = retVal.getObjectId("parentId", null);
        if (null == tmp) { // (no more parents)
            return parentCommunityId;
        }
        if (tmp.equals(parentCommunityId)) { // (shouldn't ever happen but will prevent infinite loop)
            return parentCommunityId;
        }
        parentCommunityId = tmp;
    }
}