本文整理汇总了Java中org.jongo.MongoCollection.ensureIndex方法的典型用法代码示例。如果您正苦于以下问题:Java MongoCollection.ensureIndex方法的具体用法?Java MongoCollection.ensureIndex怎么用?Java MongoCollection.ensureIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jongo.MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.ensureIndex方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUpDB
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private void setUpDB() {
LOGGER.info("Setting up DB...");
MongoCollection indexes = jongo.getCollection("system.indexes");
for (Constants.DB table : Constants.DB.values()) {
MongoCollection collection = getCollection(table);
LOGGER.info("Find indexes for table [{}].", table.getTable());
for (String index : table.getIndexes()) {
LOGGER.debug("Try to find index [{}] for table [{}].", index, table.getTable());
if (indexes.findOne("{key : # } ", index).as(Object.class) == null) {
LOGGER.debug("Cannot find index [{}] for table [{}].", index, table.getTable());
LOGGER.debug("Try to create index [{}] for table [{}].", index, table.getTable());
collection.ensureIndex(index);
LOGGER.debug("Index [{}] for table [{}] was created.", index, table.getTable());
}
}
}
LOGGER.info("DB was set up.");
}
示例2: createEvent
import org.jongo.MongoCollection; //导入方法依赖的package包/类
/**
* Stores a created event in the database.
*
* @param event An Event object.
* @return The created event.
*/
public Event createEvent(Event event) {
MongoCollection collection = db.getClient().getCollection("events");
collection.ensureIndex("{ location.coordinates: '2dsphere' }");
collection.insert(event);
return event;
}
示例3: ensureIndeces
import org.jongo.MongoCollection; //导入方法依赖的package包/类
private void ensureIndeces() {
MongoCollection reqs = jdb.getCollection(TABLE_MODULE_REQUEST);
reqs.ensureIndex("{moduleName:1,ownerUserId:1}", "{unique:true}");
reqs.ensureIndex("{ownerUserId:1}", "{unique:false}");
MongoCollection vers = jdb.getCollection(TABLE_MODULE_VERSION);
vers.ensureIndex("{moduleName:1}", "{unique:true}");
MongoCollection owns = jdb.getCollection(TABLE_MODULE_OWNER);
owns.ensureIndex("{moduleName:1,ownerUserId:1}", "{unique:true}");
owns.ensureIndex("{ownerUserId:1}", "{unique:false}");
MongoCollection infos = jdb.getCollection(TABLE_MODULE_INFO_HISTORY);
infos.ensureIndex("{moduleName:1,versionTime:1}", "{unique:true}");
MongoCollection specs = jdb.getCollection(TABLE_MODULE_SPEC_HISTORY);
specs.ensureIndex("{moduleName:1,versionTime:1}", "{unique:true}");
MongoCollection tschs = jdb.getCollection(TABLE_MODULE_TYPE_SCHEMA);
tschs.ensureIndex("{moduleName:1,typeName:1,version:1}", "{unique:true}");
tschs.ensureIndex("{moduleName:1,moduleVersion:1}", "{unique:false}");
MongoCollection tprs = jdb.getCollection(TABLE_MODULE_TYPE_PARSE);
tprs.ensureIndex("{moduleName:1,typeName:1,version:1}", "{unique:true}");
tprs.ensureIndex("{moduleName:1,moduleVersion:1}", "{unique:false}");
MongoCollection fprs = jdb.getCollection(TABLE_MODULE_FUNC_PARSE);
fprs.ensureIndex("{moduleName:1,funcName:1,version:1}", "{unique:true}");
fprs.ensureIndex("{moduleName:1,moduleVersion:1}", "{unique:false}");
MongoCollection frefs = jdb.getCollection(TABLE_FUNC_REFS);
frefs.ensureIndex("{depModule:1,depName:1,depVersion:1}", "{unique:false}");
frefs.ensureIndex("{refModule:1,refName:1,refVersion:1}", "{unique:false}");
frefs.ensureIndex("{depModule:1,depModuleVersion:1}", "{unique:false}");
MongoCollection trefs = jdb.getCollection(TABLE_TYPE_REFS);
trefs.ensureIndex("{depModule:1,depName:1,depVersion:1}", "{unique:false}");
trefs.ensureIndex("{refModule:1,refName:1,refVersion:1}", "{unique:false}");
trefs.ensureIndex("{depModule:1,depModuleVersion:1}", "{unique:false}");
}
示例4: users
import org.jongo.MongoCollection; //导入方法依赖的package包/类
/**
* Looks up the user collection from the database
* @return
*/
public static MongoCollection users() {
MongoCollection userCollection = PlayJongo.getCollection("users");
// make sure we use 2d indices on a sphere to use geospatial queries
userCollection.ensureIndex("{loc: '2dsphere'}");
return userCollection;
}
示例5: Get_DB_Collection
import org.jongo.MongoCollection; //导入方法依赖的package包/类
/**
*
* @param collection
* @param geoLoc
* @return
* @throws Exception
*/
public static MongoCollection Get_DB_Collection(MONGO_COLLECTIONS collection, String geoLoc)
throws Exception {
MongoCollection coll;
try {
Jongo jongo = new Jongo(mongoClient.getDB(DB_NAME));
coll = jongo.getCollection(collection.name());
if (StringUtils.isNotBlank(geoLoc)) { coll.ensureIndex("{"+geoLoc+": '2d'}"); }
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return coll;
}
示例6: getDisplay
import org.jongo.MongoCollection; //导入方法依赖的package包/类
/**
* Main Display Sorted by Time
* - Cons: many calls to the DB
* - Pros: Returns everything in one JSON
*
* TODO: I need to investigate utilizing additional indexes
* - http://docs.mongodb.org/manual/applications/indexes/
*
* TODO: might want to create a ttl index to remove expired data... or keep and backup:
* - http://docs.mongodb.org/manual/tutorial/expire-data/
*
* - Currently the Data Modeling Decision is to use References instead of embedding them.
* If we find that the response time is an issue we can migrate to an embedded approach.
* See: http://docs.mongodb.org/manual/core/data-modeling/
* @param geoLoc
* @return
* @throws Exception
*/
private Response getDisplay(GeoLoc geoLoc) throws Exception {
Response response;
try
{
Root root = new Root();
root.ClosestLocation = CommonBikeRideCalls.getClosestLocation(geoLoc);
//**(Get BikeRide list: 3 calls to the DB)**
DateTime nowDateTime = new DateTime(DateTimeZone.UTC); // Joda time
DateTime maxStartTime = nowDateTime.plusMinutes(TIME_IN_MINUTES);
DateTime minStartTime = nowDateTime.minusDays(1); //This will cut out most old bike rides
Long now = nowDateTime.toInstant().getMillis();
Long max = maxStartTime.toInstant().getMillis();
Long min = minStartTime.toInstant().getMillis();
//Get the objects using Jongo
MongoCollection bikeRidesCollection = MongoDatabase.Get_DB_Collection(MONGO_COLLECTIONS.BIKERIDES, "location.geoLoc");
//Currently not placing a limit on this result. If we find this is an issue we can add later.
bikeRidesCollection.ensureIndex("{location.geoLoc: '2d', rideStartTime: 1}");
Iterable<BikeRide> all = bikeRidesCollection
.find("{location.geoLoc: {$near: [#, #], $maxDistance: #}, rideStartTime: {$lte: #, $gte: #}}",
geoLoc.longitude,
geoLoc.latitude,
RADIUS_IN_MILES/SharedStaticValues.ONE_DEGREE_IN_MILES,
max ,
min )
.fields(SharedStaticValues.MAIN_PAGE_DISPLAY_FIELDS)
.as(BikeRide.class);
List<BikeRide> closeBikeRides = Lists.newArrayList(all);
//**(Set tracking on bike rides: 2 DB call)
closeBikeRides = CommonBikeRideCalls.postBikeRideDBUpdates(closeBikeRides, geoLoc);
for(BikeRide closeBikeRide : closeBikeRides) {
//Find all rides that haven't started AND find all bike rides still being tracked.
if (closeBikeRide.rideStartTime > now || closeBikeRide.currentlyTracking) {
root.BikeRides.add(closeBikeRide);
}
}
response = Response.status(Response.Status.OK).entity(root).build();
}
catch (Exception e)
{
e.printStackTrace();
LOG.error("DisplayByProximity Failed", e);
response = Response.status(Response.Status.PRECONDITION_FAILED).entity("Error: " + e).build();
}
return response;
}