本文整理汇总了Java中com.mongodb.DBObject.put方法的典型用法代码示例。如果您正苦于以下问题:Java DBObject.put方法的具体用法?Java DBObject.put怎么用?Java DBObject.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.DBObject
的用法示例。
在下文中一共展示了DBObject.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextId
import com.mongodb.DBObject; //导入方法依赖的package包/类
public int getNextId(GridFS destDatabase) {
DBCollection countersCollection = destDatabase.getDB().getCollection("counters");
DBObject record = countersCollection.findOne(new BasicDBObject("_id", "package"));
if (record == null) {
BasicDBObject dbObject = new BasicDBObject("_id", "package");
dbObject.append("seq", 0);
countersCollection.insert(dbObject);
record = dbObject;
}
int oldID = (int) record.get("seq");
int newID = oldID + 1;
record.put("seq", newID);
countersCollection.update(new BasicDBObject("_id", "package"), record);
return newID;
}
示例2: insert
import com.mongodb.DBObject; //导入方法依赖的package包/类
public void insert(List<CanalEntry.Column> data, String schemaName, String tableName) {
DBObject obj = DBConvertUtil.columnToJson(data);
logger.debug("insert :{}", obj.toString());
//订单库单独处理
if (schemaName.equals("order")) {
//保存原始数据
if (tableName.startsWith("order_base_info")) {
tableName = "order_base_info";
} else if (tableName.startsWith("order_detail_info")) {
tableName = "order_detail_info";
} else {
logger.info("unknown data :{}.{}:{}", schemaName, tableName, obj);
return;
}
insertData(schemaName, tableName, obj, obj);
} else {
DBObject newObj = (DBObject) ObjectUtils.clone(obj);
if (newObj.containsField("id")) {
newObj.put("_id", newObj.get("id"));
newObj.removeField("id");
}
insertData(schemaName, tableName, newObj, obj);
}
}
示例3: getCondition
import com.mongodb.DBObject; //导入方法依赖的package包/类
private Condition getCondition() throws DBException
{
final DBObject query = type == 0 ? new BasicDBObject() : this.query;
if (type == 0 && regexNameValues != null)
{
String[] names = regexNameValues.getNames();
Object[] values = regexNameValues.getValues();
for (int i = 0; i < names.length; i++)
{
query.put(names[i], new BasicDBObject("$regex", values[i]));
}
}
MongoCondition mongoCondition = new MongoCondition()
{
public Object toFinalObject() throws Condition.ConditionException
{
return query;
}
};
return mongoCondition;
}
示例4: doBatchUpdate
import com.mongodb.DBObject; //导入方法依赖的package包/类
private int doBatchUpdate(DBCollection dbCollection, String collName, Collection<BatchUpdateOptions> options,
boolean ordered) {
DBObject command = new BasicDBObject();
command.put("update", collName);
List<BasicDBObject> updateList = new ArrayList<BasicDBObject>();
for (BatchUpdateOptions option : options) {
BasicDBObject update = new BasicDBObject();
update.put("q", option.getQuery().getQueryObject());
update.put("u", option.getUpdate().getUpdateObject());
update.put("upsert", option.isUpsert());
update.put("multi", option.isMulti());
updateList.add(update);
}
command.put("updates", updateList);
command.put("ordered", ordered);
CommandResult commandResult = dbCollection.getDB().command(command);
return Integer.parseInt(commandResult.get("n").toString());
}
示例5: cryptFields
import com.mongodb.DBObject; //导入方法依赖的package包/类
void cryptFields(DBObject dbObject, Node node, Function<Object, Object> crypt) {
if (node.type == Node.Type.MAP) {
Node mapChildren = node.children.get(0);
for (Map.Entry<String, Object> entry : ((BasicDBObject) dbObject).entrySet()) {
cryptFields((DBObject) entry.getValue(), mapChildren, crypt);
}
return;
}
for (Node childNode : node.children) {
Object value = dbObject.get(childNode.fieldName);
if (value == null) continue;
if (!childNode.children.isEmpty()) {
if (value instanceof BasicDBList) {
for (Object o : (BasicDBList) value)
cryptFields((DBObject) o, childNode, crypt);
} else {
cryptFields((BasicDBObject) value, childNode, crypt);
}
return;
}
dbObject.put(childNode.fieldName, crypt.apply(value));
}
}
示例6: insert
import com.mongodb.DBObject; //导入方法依赖的package包/类
public Object insert(DBCollection collection, WriteConcern writeConcern) {
DBObject document = new BasicDBObject();
// 匹配_id
for (int i = 0, n = columns.size(); i < n; i++) {
// document.put(columns.get(i), values.get(i).getValue());
String tempColumn = columns.get(i);
if (3 == tempColumn.length() && tempColumn.equals("_id")) {
document.put(tempColumn, new ObjectId(values.get(i).getValue().toString()));
} else {
document.put(tempColumn, values.get(i).getValue());
}
}
log(document);
// TODO: WriteConcern.ACKNOWLEDGED需要可以配置
// WriteResult result = collection.insert(document, WriteConcern.ACKNOWLEDGED);
// collection.insert(document, MongoComponent.getInstance().getDefaultWriteConcern());
collection.insert(document, writeConcern);
Object oid = document.get("_id");
if (null != oid) {
return oid.toString();
}
return null;
}
示例7: logError
import com.mongodb.DBObject; //导入方法依赖的package包/类
/**
* 记录拼接表错误记录
*
* @param schemaName
* @param tableName
* @param event 1:INSERT;2:UPDATE;3:DELETE
* @param step 0:预处理数据错误;1:保存原始数据错误;2:保存组合数据错误,
* @param obj
* @param e
*/
private void logError(String schemaName, String tableName, int event, int step, DBObject obj, Exception e) {
logger.error("error data:name[{},{}] , eventType : {} , data : [{}]", schemaName, tableName, event, obj);
DBObject errObj = new BasicDBObject();
errObj.put("schemaName", schemaName);
errObj.put("tableName", tableName);
errObj.put("event", event);
errObj.put("data", obj);
errObj.put("step", step);
errObj.put("time", new Date());
errObj.put("error", e.toString());
completeMongoTemplate.getCollection(NameConst.C_ERROR_RECORD).insert(errObj);
}
示例8: setQuery
import com.mongodb.DBObject; //导入方法依赖的package包/类
@Override
public void setQuery(DBObject query, BasicDBList orList) {
if (null == orList) {
query.put(this.name, new BasicDBObject("$lte", value.getValue()));
} else {
orList.add(new BasicDBObject(this.name, new BasicDBObject("$lte", value.getValue())));
}
}
示例9: modifyGlbFile
import com.mongodb.DBObject; //导入方法依赖的package包/类
public void modifyGlbFile(int rid, double lon, double lat) {
Query query = new Query();
query.addCriteria(Criteria.where("metadata.rid").is(rid).andOperator(Criteria.where("metadata." + STORE_BIM_TYPE).is(STORE_GLB_FILE)));
GridFSDBFile file = gridFsTemplate.findOne(query);
DBObject metaData = file.getMetaData();
metaData.put("lon", lon);
metaData.put("lat", lat);
file.save();
}
示例10: saveGlbOffline
import com.mongodb.DBObject; //导入方法依赖的package包/类
public GridFSFile saveGlbOffline(InputStream inputStream, String fileName, Long id, double lon, double lat) {
DBObject metaData = new BasicDBObject("offline", true);
metaData.put("id", id);
metaData.put(STORE_BIM_TYPE, STORE_GLB_FILE);
metaData.put("lon", lon);
metaData.put("lat", lat);
return gridFsTemplate.store(inputStream, fileName, metaData);
}
示例11: put
import com.mongodb.DBObject; //导入方法依赖的package包/类
@Override
public void put(String key, V value) {
try {
DBObject putObj = new BasicDBObject(2);
putObj.put(ID, key);
putObj.put(pKey, bytes(value));
collection.insert(putObj);
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new DrillRuntimeException(e.getMessage(), e);
}
}
示例12: testGridFs
import com.mongodb.DBObject; //导入方法依赖的package包/类
@Test
public void testGridFs() throws IOException {
// 创建测试文件
FileUtils.createTestFile();
// 文件元信息
DBObject metaData = new BasicDBObject();
metaData.put("extra1", "anything 1");
metaData.put("extra2", "anything 2");
// 获得文件流并保存
InputStream inputStream = new FileInputStream(testFileName);
gridFsOperations.store(inputStream, testFileName, metaData);
inputStream.close();
// 查询保存的文件
List<GridFSDBFile> result = gridFsOperations.find(query(whereFilename().is(testFileName)));
Assert.assertEquals(result.size(), 1);
// 删除保存的文件
gridFsOperations.delete(query(whereFilename().is(testFileName)));
// 查询删除的文件
result = gridFsOperations.find(query(whereFilename().is(testFileName)));
Assert.assertEquals(result.size(), 0);
// 删除测试文件
FileUtils.removeTestFile();
}
示例13: put
import com.mongodb.DBObject; //导入方法依赖的package包/类
@Override
public void put(String email, String password) {
DBObject object = new BasicDBObject();
object.put(FIELD_EMAIL, email);
object.put(FIELD_PASSWORD, password);
collection.insert(object);
}
示例14: convert
import com.mongodb.DBObject; //导入方法依赖的package包/类
@Override
protected DBObject convert(MongoSession source) {
try {
DBObject dbSession = (DBObject) JSON.parse(this.objectMapper.writeValueAsString(source));
dbSession.put(PRINCIPAL_FIELD_NAME, extractPrincipal(source));
return dbSession;
} catch (JsonProcessingException e) {
throw new IllegalStateException("Cannot convert MongoExpiringSession", e);
}
}
开发者ID:spring-projects,项目名称:spring-session-data-mongodb,代码行数:12,代码来源:JacksonMongoSessionConverter.java
示例15: getFields
import com.mongodb.DBObject; //导入方法依赖的package包/类
private DBObject getFields() {
if (null != this.allColumn) {
return null;
}
DBObject fields = new BasicDBObject();
// fields.put("_id", 0);
for (int i = 0, n = columns.size(); i < n; i++) {
// fields.put(columns.get(i), true);
fields.put(columns.get(i), 1);// 1代表需要指定显示的列
}
return fields;
}