本文整理汇总了Java中com.mongodb.BasicDBObject.append方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDBObject.append方法的具体用法?Java BasicDBObject.append怎么用?Java BasicDBObject.append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.BasicDBObject
的用法示例。
在下文中一共展示了BasicDBObject.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getNextId
import com.mongodb.BasicDBObject; //导入方法依赖的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: parse
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/**
* 解析
* @param group
* @param parser
* @return
*/
@Override
public Object parse(IGroup group, JsonRuleParser parser) {
// rules
BasicDBList operates = new BasicDBList();
for (JsonRule jsonRule : group.getRules()) {
operates.add(parser.parse(jsonRule));
}
// AND or OR
BasicDBObject andOrObj = new BasicDBObject();
andOrObj.append(EnumCondition.AND.equals(group.getCondition()) ? "$and" : "$or", operates);
// Not
if (group.getNot() != null && group.getNot()) {
BasicDBList list = new BasicDBList();
list.add(andOrObj);
return new BasicDBObject("$nor", list);
}
return andOrObj;
}
示例3: updateUserChangeNameAndSurnametoName
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/**
* update 6: {@link UserDocument} has changed; 'name' and 'surname' will be concat to 'name'.
* for each every user document get 'name' and 'surname', concat them, update 'name', remove field surname and update document.
*
* @since V7
*/
@ChangeSet(order = "008", id = "updateUserChangeNameAndSurnameToName", author = "admin")
public void updateUserChangeNameAndSurnametoName(final MongoTemplate template) {
final DBCollection userCollection = template.getCollection("user");
final Iterator<DBObject> cursor = userCollection.find();
while (cursor.hasNext()) {
final DBObject current = cursor.next();
final Object nameObj = current.get("name");
final Object surnameObj = current.get("surname");
final String updateName = (nameObj != null ? nameObj.toString() : "") + " " + (surnameObj != null ? surnameObj.toString() : "");
final BasicDBObject updateQuery = new BasicDBObject();
updateQuery.append("$set", new BasicDBObject("name", updateName));
updateQuery.append("$unset", new BasicDBObject("surname", ""));
final BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("_id", current.get("_id"));
userCollection.update(searchQuery, updateQuery);
}
}
示例4: setMonitored
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
public AgentFull setMonitored(String agentId, boolean monitored){
AgentFull agent = getAgentByAgentId(agentId);
if (agent != null){
agent.setMonitored(monitored);
//Preparing to insert new field
BasicDBObject updateMonitored = new BasicDBObject();
updateMonitored.append("$set", new BasicDBObject().append("monitored", monitored));
//Find the register with the specified ID
BasicDBObject searchById = new BasicDBObject();
searchById.append("agentId", agentId);
//Launch the update
getAgentTable().updateMulti(searchById, updateMonitored);
return getAgentByAgentId(agentId);
}
else {
return null;
}
}
示例5: getDBObject
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/** Return an object suitable to create a new user in MongoDB. */
public BasicDBObject getDBObject(boolean includeId) {
BasicDBObject user = new BasicDBObject();
if (includeId) {
user.append(DB_ID, new ObjectId(id));
}
user.append(JSON_KEY_USER_FIRST_NAME, firstName);
user.append(JSON_KEY_USER_LAST_NAME, lastName);
user.append(JSON_KEY_USER_NAME, userName);
user.append(JSON_KEY_USER_TWITTER_HANDLE, twitterHandle);
user.append(JSON_KEY_USER_WISH_LIST_LINK, wishListLink);
user.append(JSON_KEY_USER_PASSWORD_HASH, passwordHash);
user.append(JSON_KEY_USER_PASSWORD_SALT, passwordSalt);
user.append(JSON_KEY_USER_TWITTER_LOGIN, isTwitterLogin);
return user;
}
示例6: getDBObjectForModify
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/**
* Return a DBObject that can be used for updating the user in the mongo database. We only include
* the fields that the client should be changing (leave out the internal fields).
*/
public DBObject getDBObjectForModify() {
BasicDBObject user = new BasicDBObject();
user.append(JSON_KEY_USER_FIRST_NAME, firstName);
user.append(JSON_KEY_USER_LAST_NAME, lastName);
user.append(JSON_KEY_USER_WISH_LIST_LINK, wishListLink);
// If the user logs in with Twitter, don't let them change their
// twitter handle, username, or password.
if (isTwitterLogin == false) {
user.append(JSON_KEY_USER_TWITTER_HANDLE, twitterHandle);
if (userName != null) {
user.append(JSON_KEY_USER_NAME, userName);
}
if (passwordHash != null) {
user.append(JSON_KEY_USER_PASSWORD_HASH, passwordHash);
}
if (passwordSalt != null) {
user.append(JSON_KEY_USER_PASSWORD_SALT, passwordSalt);
}
}
return user;
}
示例7: getDBObject
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/**
* Create a Mongo DB Object baed on the content of this group
*
* @param id The Mongo Object id to assign to this DB Object. If null, a new Object id will be
* created
* @return - The Mongo DB Object based on the content of this group
*/
public BasicDBObject getDBObject(boolean includeId) {
BasicDBObject group = new BasicDBObject();
if (includeId) {
group.append(DB_ID, new ObjectId(id));
}
group.append(JSON_KEY_GROUP_NAME, name);
BasicDBList membersArray = new BasicDBList();
for (int i = 0; i < members.length; i++) {
membersArray.add(members[i]);
}
group.append(JSON_KEY_MEMBERS_LIST, membersArray);
return group;
}
示例8: getDBObject
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/**
* Create a Mongo DB Object baed on the content of this group
*
* @param id The Mongo Object id to assign to this DB Object. If null, a new Object id will be
* created
* @return - The Mongo DB Object based on the content of this group
*/
public BasicDBObject getDBObject(boolean includeId) {
BasicDBObject group = new BasicDBObject();
if (includeId) {
group.append(DB_ID, new ObjectId(id));
}
group.append(JSON_KEY_GROUP_NAME, name);
BasicDBList membersArray = new BasicDBList();
for (int i = 0; i < members.length; i++) {
membersArray.add(members[i]);
}
group.append(JSON_KEY_MEMBERS_LIST, membersArray);
return group;
}
示例9: insertReportTest
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
@Test
public void insertReportTest()
{
Report.Builder rBuilder = new Report.Builder();
rBuilder.reportDate(new Date());
rBuilder.resolveDate(new Date());
rBuilder.resolved(true);
rBuilder.comment("comment99");
rBuilder.priority("high");
Report report = new Report();
report = rBuilder.build();
CityItemDAO.insertReport(report);
BasicDBObject query = new BasicDBObject();
query.append("report.comment","comment99");
Document result = Configurator.INSTANCE.getDatabase().getCollection("city_items").find().first();
Assert.assertTrue("Result should not be null",result != null);
}
示例10: getBasicDBObject
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
private BasicDBObject getBasicDBObject(HttpServletRequest request, JoinPoint joinPoint) {
// 基本信息
BasicDBObject r = new BasicDBObject();
r.append("requestURL", request.getRequestURL().toString());
r.append("requestURI", request.getRequestURI());
r.append("queryString", request.getQueryString());
r.append("remoteAddr", request.getRemoteAddr());
r.append("remoteHost", request.getRemoteHost());
r.append("remotePort", request.getRemotePort());
r.append("localAddr", request.getLocalAddr());
r.append("localName", request.getLocalName());
r.append("method", request.getMethod());
r.append("headers", getHeadersInfo(request));
r.append("parameters", request.getParameterMap());
r.append("classMethod", joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
r.append("args", Arrays.toString(joinPoint.getArgs()));
return r;
}
示例11: concretProcessor
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
@Override
public void concretProcessor(Object expKey, Map expValue, BasicDBObject set) {
Map expressions = (Map) expValue.get(expKey);
Set keys = expressions.keySet();
Iterator iter = keys.iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
Object value = expressions.get(key);
if (value instanceof Map) {
KVStrategy kv = new KVStrategy();
kv.concretProcessor(key, expressions, set);
}
else {
set.append(key, value);
log.info(this, "@key: " + key + "@value:" + value);
}
}
}
示例12: parse
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
public DBObject parse(IRule rule, JsonRuleParser parser) {
List<Object> values = (List<Object>) rule.getValue();
BasicDBObject operate = new BasicDBObject();
operate.append("$gte", values.get(0));
operate.append("$lte", values.get(1));
return new BasicDBObject(rule.getField(), operate);
}
示例13: parse
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
public BasicDBObject parse(IRule rule, JsonRuleParser parser) {
List<Object> values = (List<Object>) rule.getValue();
BasicDBObject operate = new BasicDBObject();
operate.append("$lt", values.get(0));
operate.append("$gt", values.get(1));
return new BasicDBObject(rule.getField(), operate);
}
示例14: getDBObject
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
public BasicDBObject getDBObject(boolean includeId) {
BasicDBObject user = new BasicDBObject();
if (includeId) {
user.append(DB_ID, new ObjectId(id));
}
user.append(JSON_KEY_USER_FIRST_NAME, firstName);
user.append(JSON_KEY_USER_LAST_NAME, lastName);
user.append(JSON_KEY_USER_NAME, userName);
user.append(JSON_KEY_USER_TWITTER_HANDLE, twitterHandle);
user.append(JSON_KEY_USER_WISH_LIST_LINK, wishListLink);
user.append(JSON_KEY_USER_PASSWORD, password);
return user;
}
示例15: cityItemExistsTest
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
@Test
public void cityItemExistsTest()
{
BasicDBObject query1 = new BasicDBObject();
query1.append("type","lamp4");
BasicDBObject doc1 = collection.find(query1).first();
BasicDBObject result1 = collection.find(doc1).first();
Assert.assertTrue("Document should exist",result1 != null);
BasicDBObject query2 = new BasicDBObject();
query2.append("type","test"); // not type as test
result1 = collection.find(query2).first();
Assert.assertTrue("Document should not exist",result1 == null);
}