本文整理汇总了Java中com.mongodb.BasicDBObjectBuilder.add方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDBObjectBuilder.add方法的具体用法?Java BasicDBObjectBuilder.add怎么用?Java BasicDBObjectBuilder.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.BasicDBObjectBuilder
的用法示例。
在下文中一共展示了BasicDBObjectBuilder.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBetweenFilter
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
private DBObject createBetweenFilter(Object value) {
JSONObject dateRange = parseDateRange(value);
org.joda.time.format.DateTimeFormatter parser = ISODateTimeFormat.dateTime();
BasicDBObjectBuilder start = BasicDBObjectBuilder.start();
if (dateRange.get("startDate") != null) {
DateTime startDate = parser.parseDateTime((String) dateRange.get("startDate"));
start.add(QueryOperators.GTE, startDate.toDate());
}
if (dateRange.get("endDate") != null) {
DateTime endDate = parser.parseDateTime((String) dateRange.get("endDate"));
start.add(QueryOperators.LTE, endDate.toDate());
}
return start.get();
}
示例2: toDBObject
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
/**
* Serializes {@link RyaDetails} to mongo {@link DBObject}.
* @param details - The details to be serialized.
* @return The mongo {@link DBObject}.
*/
public static BasicDBObject toDBObject(final RyaDetails details) {
Preconditions.checkNotNull(details);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start()
.add(INSTANCE_KEY, details.getRyaInstanceName())
.add(VERSION_KEY, details.getRyaVersion())
.add(ENTITY_DETAILS_KEY, details.getEntityCentricIndexDetails().isEnabled())
//RYA-215 .add(GEO_DETAILS_KEY, details.getGeoIndexDetails().isEnabled())
.add(PCJ_DETAILS_KEY, toDBObject(details.getPCJIndexDetails()))
.add(TEMPORAL_DETAILS_KEY, details.getTemporalIndexDetails().isEnabled())
.add(FREETEXT_DETAILS_KEY, details.getFreeTextIndexDetails().isEnabled());
if(details.getProspectorDetails().getLastUpdated().isPresent()) {
builder.add(PROSPECTOR_DETAILS_KEY, details.getProspectorDetails().getLastUpdated().get());
}
if(details.getJoinSelectivityDetails().getLastUpdated().isPresent()) {
builder.add(JOIN_SELECTIVITY_DETAILS_KEY, details.getJoinSelectivityDetails().getLastUpdated().get());
}
return (BasicDBObject) builder.get();
}
示例3: toDBObject
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
/**
* Serializes a {@link DocumentVisibility} to a MongoDB {@link DBObject}.
* @param documentVisibility the {@link DocumentVisibility} to be
* serialized.
* @return The MongoDB {@link DBObject}.
*/
public static BasicDBObject toDBObject(final DocumentVisibility documentVisibility) {
DocumentVisibility dv;
if (documentVisibility == null) {
dv = MongoDbRdfConstants.EMPTY_DV;
} else {
dv = documentVisibility;
}
Object[] dvArray = null;
try {
dvArray = DocumentVisibilityUtil.toMultidimensionalArray(dv);
} catch (final DocumentVisibilityConversionException e) {
log.error("Unable to convert document visibility");
}
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
builder.add(DOCUMENT_VISIBILITY_KEY, dvArray);
return (BasicDBObject) builder.get();
}
示例4: serialize
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
@Override
public DBObject serialize(final RyaStatement ryaStatement) {
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start("_id", ryaStatement.getSubject().hashCode());
final URI obj = ryaStatement.getObject().getDataType();
if(obj.equals(GeoConstants.GEO_AS_WKT) || obj.equals(GeoConstants.GEO_AS_GML) ||
obj.equals(GeoConstants.XMLSCHEMA_OGC_GML) || obj.equals(GeoConstants.XMLSCHEMA_OGC_WKT)) {
try {
final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement);
final Geometry geo = GeoParseUtils.getGeometry(statement, new GmlParser());
if (geo.getNumPoints() > 1) {
builder.add(GEO_KEY, geoStrategy.getCorrespondingPoints(geo));
} else {
builder.add(GEO_KEY, geoStrategy.getDBPoint(geo));
}
} catch (final ParseException e) {
LOG.error("Could not create geometry for statement " + ryaStatement, e);
return null;
}
} else {
builder.add(TIME_KEY, temporalStrategy.getTimeValue(ryaStatement.getObject().getData()));
}
return builder.get();
}
示例5: initialize
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
public void initialize() {
// Make sure the fields we want to query are indexed
DBCollection assets = db.getCollection(ASSETS_COLLECTION);
DBCollection attachments = db.getCollection(ATTACHMENTS_COLLECTION);
// Add text index
BasicDBObjectBuilder textIndex = BasicDBObjectBuilder.start();
for (String indexField : searchIndexFields) {
textIndex.add(indexField, "text");
}
assets.ensureIndex(textIndex.get());
// Add Attachment(assetId) index
attachments.ensureIndex(new BasicDBObject("assetId", 1));
}
示例6: mapReduce
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
public ObjectListPresentation mapReduce(String map, String reduce, Bindings options) {
BasicDBObjectBuilder command = new BasicDBObjectBuilder();
command.add("mapReduce", name);
command.add("map", map);
command.add("reduce", reduce);
putObject("query", options, command);
putObject("out", options, command);
putObject("scope", options, command);
putSimpleField("field", options, command);
putSimpleField("jsMode", options, command);
putSimpleField("finilize", options, command);
putSimpleField("verbose", options, command);
return singletonIter(mongoDatabase.getMongoDb().runCommand((Bson)command.get()));
}
示例7: update
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
@Override
public boolean update(JID jid, String affiliation) {
try {
// {"affiliations.$.affiliation":Xxx}
BasicDBObjectBuilder entity = BasicDBObjectBuilder.start().add(Dictionary.FIELD_AFFILIATIONS + ".$." + Dictionary.FIELD_AFFILIATION, affiliation);
if (ItemAffiliation.OWNER.equals(affiliation)) {
// {"creator":jid.bare}
// 如果为Owner则同时更新创建者
entity.add(Dictionary.FIELD_CREATOR, jid.asStringWithBare());
}
// {"jid":group.bare,"affiliations.jid":jid.bare"},{"$set":...entity...}
return MongoUtils.success(MongoAffiliationBuilder.this.config.collection().update(BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, this.group.asStringWithBare()).add(Dictionary.FIELD_AFFILIATIONS + "." + Dictionary.FIELD_JID, jid.asStringWithBare()).get(), BasicDBObjectBuilder.start().add("$set", entity.get()).get(), true, false, WriteConcern.SAFE));
} catch (MongoException e) {
// {"jid":group.bare},{"$addToSet":{"affiliations":{"jid":Xxx,"affiliation":Xxx}}}
return MongoUtils.success(MongoAffiliationBuilder.this.config.collection().update(BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, this.group.asStringWithBare()).get(), BasicDBObjectBuilder.start("$addToSet", BasicDBObjectBuilder.start(Dictionary.FIELD_AFFILIATIONS, BasicDBObjectBuilder.start().add(Dictionary.FIELD_JID, jid.asStringWithBare()).add(Dictionary.FIELD_AFFILIATION, affiliation).get()).get()).get(), true, false, WriteConcern.SAFE));
}
}
示例8: log
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
@Override
public void log(String driverId, String test, String testRun, LogLevel level, String msg)
{
BasicDBObjectBuilder insertObjBuilder = BasicDBObjectBuilder.start()
.add(FIELD_TIME, new Date())
.add(FIELD_LEVEL, level.getLevel())
.add(FIELD_MSG, msg);
if (driverId != null)
{
insertObjBuilder.add(FIELD_DRIVER_ID, driverId);
}
if (test != null)
{
insertObjBuilder.add(FIELD_TEST, test);
}
if (testRun != null)
{
insertObjBuilder.add(FIELD_TEST_RUN, testRun);
}
DBObject insertObj = insertObjBuilder.get();
collection.insert(insertObj);
}
示例9: countUsers
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
@Override
public long countUsers(String domain, DataCreationState creationState)
{
BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start();
if (domain != null)
{
queryObjBuilder.add(FIELD_DOMAIN, domain);
}
if (creationState != null)
{
queryObjBuilder.add(FIELD_CREATION_STATE, creationState.toString());
}
DBObject queryObj = queryObjBuilder.get();
return collection.count(queryObj);
}
示例10: getData
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
@Override
public DBCursor getData(String driverId, String test, String testRun, String sheetName)
{
// check params
checkMandatoryString(test, "test");
checkMandatoryString(testRun, "testRun");
checkMandatoryString(sheetName, "sheetName");
// create query
BasicDBObjectBuilder queryObjBuilder = BasicDBObjectBuilder.start();
if (null != driverId && !driverId.isEmpty())
{
queryObjBuilder.add(FIELD_DRIVER_ID, driverId);
}
queryObjBuilder.add(FIELD_TEST, test).add(FIELD_TEST_RUN, testRun).add(FIELD_SHEET_NAME, sheetName);
DBObject queryObj = queryObjBuilder.get();
// sort and return cursor
DBCursor dbCursor = this.collectionExtraData.find(queryObj);
return dbCursor;
}
示例11: getMongo
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
private Measurements getMongo(MeasurementFilter request) {
BasicDBObjectBuilder q = new BasicDBObjectBuilder();
if (request.hasSpatialFilter()) {
SpatialFilter sf = request.getSpatialFilter();
try {
q.add(MongoMeasurement.GEOMETRY,
MongoUtils.spatialFilter(sf, geometryConverter));
} catch (GeometryConverterException e) {
log.error("Error while applying spatial filter: " + e
.getLocalizedMessage());
}
}
if (request.hasTrack()) {
q.add(MongoMeasurement.TRACK, ref(request.getTrack()));
}
if (request.hasUser()) {
q.add(MongoMeasurement.USER, ref(request.getUser()));
}
if (request.hasTemporalFilter()) {
q.add(MongoMeasurement.TIME,
MongoUtils.temporalFilter(request.getTemporalFilter()));
}
return query(q.get(), request.getPagination());
}
示例12: matches
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
private DBObject matches(StatisticsFilter request) {
BasicDBObjectBuilder b = new BasicDBObjectBuilder();
BasicDBObjectBuilder match = b.push(Ops.MATCH);
if (request.hasTrack()) {
DBRef track = mongoDB.ref(request.getTrack());
match.add(MongoMeasurement.TRACK, track);
}
if (request.hasUser()) {
DBRef user = mongoDB.ref(request.getUser());
match.add(MongoMeasurement.USER, user);
}
if (request.hasSensor()) {
MongoSensor sensor = (MongoSensor) request.getSensor();
match.add(SENSOR_ID_PATH, sensor.getId());
}
return b.get();
}
示例13: ensureIndex
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
/**
* Ensures (creating if necessary) the index including the field(s) + directions; eg fields = "field1, -field2" ({field1:1, field2:-1})
*/
public void ensureIndex(String collName, String name, String fields, boolean unique, boolean dropDupsOnCreate) {
BasicDBObject dbFields = parseFieldsString(fields);
final BasicDBObjectBuilder keyOpts = new BasicDBObjectBuilder();
if (name != null && name.length() != 0) {
keyOpts.add("name", name);
}
if (unique) {
keyOpts.add("unique", true);
if (dropDupsOnCreate) {
keyOpts.add("dropDups", true);
}
}
final DBCollection dbColl = getCollection(getCollName(collName));
final BasicDBObject opts = (BasicDBObject) keyOpts.get();
if (opts.isEmpty()) {
LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + dbFields);
dbColl.createIndex(dbFields);
} else {
LOGGER.debug("Ensuring index for " + dbColl.getName() + " with keys:" + fields + " and opts:" + opts);
dbColl.createIndex(dbFields, opts);
}
}
示例14: parseFieldsString
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
private BasicDBObject parseFieldsString(final String fields) {
BasicDBObjectBuilder ret = BasicDBObjectBuilder.start();
final String[] parts = fields.split(",");
for (String s : parts) {
s = s.trim();
int dir = 1;
if (s.startsWith("-")) {
dir = -1;
s = s.substring(1).trim();
}
ret = ret.add(s, dir);
}
return (BasicDBObject) ret.get();
}
示例15: getTimeValue
import com.mongodb.BasicDBObjectBuilder; //导入方法依赖的package包/类
public DBObject getTimeValue(final String timeData) {
final Matcher match = TemporalInstantRfc3339.PATTERN.matcher(timeData);
final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
if(match.find()) {
final TemporalInterval date = TemporalInstantRfc3339.parseInterval(timeData);
builder.add(INTERVAL_START, date.getHasBeginning().getAsDateTime().toDate());
builder.add(INTERVAL_END, date.getHasEnd().getAsDateTime().toDate());
} else {
builder.add(INSTANT, TemporalInstantRfc3339.FORMATTER.parseDateTime(timeData).toDate());
}
return builder.get();
}