当前位置: 首页>>代码示例>>Java>>正文


Java UpdateResult.getModifiedCount方法代码示例

本文整理汇总了Java中com.mongodb.client.result.UpdateResult.getModifiedCount方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateResult.getModifiedCount方法的具体用法?Java UpdateResult.getModifiedCount怎么用?Java UpdateResult.getModifiedCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.client.result.UpdateResult的用法示例。


在下文中一共展示了UpdateResult.getModifiedCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: upsert

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
/**
 * 新增或者更新
 *
 * @param collectionName 集合名
 * @param query          查询条件
 * @param descData       目标数据
 * @return
 */
public boolean upsert(String collectionName, MongodbQuery query, Map<String, Object> descData) {
    MongoCollection collection = sMongoDatabase.getCollection(collectionName);
    UpdateOptions options = new UpdateOptions();
    options.upsert(true);
    BasicDBObject updateSetValue = new BasicDBObject("$set", descData);
    UpdateResult updateResult = collection.updateMany(query.getQuery(), updateSetValue, options);
    return updateResult.getUpsertedId() != null ||
            (updateResult.getMatchedCount() > 0 && updateResult.getModifiedCount() > 0);
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:18,代码来源:MongodbDataAccess.java

示例2: updateNote

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
@PUT
@Path("{id}")
public Response updateNote(Note note) {
    note.setModified(LocalDateTime.now());
    note.setUser(user.getId());
    UpdateResult result = 
            collection.updateOne(buildQueryById(note.getId()),
            new Document("$set", note.toDocument()));
    if (result.getModifiedCount() == 0) {
        return Response.status(Response.Status.NOT_FOUND).build();
    } else {
        return Response.ok().build();
    }
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:15,代码来源:NoteResource.java

示例3: executeQuery

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
@Override
long executeQuery(int threadId, long threadRunCount, long globalRunCount, long selectorId, long randomId){

    final Document doc = new Document("$set", new Document(RANDOM_LONG, randomId))
            .append("$inc", new Document(VERSION, 1));

    final UpdateResult res = THREAD_RUN_COUNT.equals(queriedField)?mongoCollection.updateMany(eq(queriedField, selectorId), doc)
            :ID.equals(queriedField)?mongoCollection.updateOne(eq(queriedField, selectorId), doc):null;
    return res!=null?res.getModifiedCount():0l;
}
 
开发者ID:idealo,项目名称:mongodb-performance-test,代码行数:11,代码来源:UpdateOperation.java

示例4: update

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
@Override
public void update(LaboratoryConfiguration configuration) throws Exception {
	Document parsed = Document.parse(LaboratoryConfiguration.serialize(configuration));
	parsed.remove("_id");

	UpdateResult updatedData = collection.updateOne(eq("_id", configuration.getId()), new Document("$set", parsed),
			new UpdateOptions().upsert(false));

	if (updatedData.getModifiedCount() == 0) {
		throw new Exception("Update was not executed.");
	}
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:13,代码来源:LaboratoryConfigurationDaoBean.java

示例5: inc

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
/**
 * inc.
 *
 * @param table
 *            the table
 * @param q
 *            the q
 * @param name
 *            the name
 * @param n
 *            the n
 * @param db
 *            the db
 * @return the int
 */
public int inc(String table, W q, String name, int n, V v, String db) {
	Document d = new Document();

	try {
		d.put(name, n);
		MongoCollection<Document> c = getCollection(db, table);
		Document d2 = new Document("$inc", d);

		Document d1 = null;
		if (v != null) {
			d1 = new Document();
			for (String s : v.names()) {
				Object v1 = v.value(s);
				d1.append(s, v1);
			}
			d2.append("$set", d1);
		}

		UpdateResult r = c.updateMany(q.query(), d2);

		if (log.isDebugEnabled())
			log.debug("updated collection=" + table + ", query=" + q + ", d=" + d + ", n=" + r.getModifiedCount()
					+ ",result=" + r);

		return (int) r.getModifiedCount();
	} catch (Exception e) {
		if (log.isErrorEnabled())
			log.error(e.getMessage(), e);
	}
	return 0;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:47,代码来源:MongoHelper.java

示例6: updateOne

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
@Override
public boolean updateOne(String docName, Document doc, Document docFilter) {
    UpdateResult upResult = baseUpdateOne(docName, doc, docFilter);
    if (upResult == null) {
        return false;
    }
    long matched = upResult.getMatchedCount();//匹配上的数据条数
    long modified = upResult.getModifiedCount();//已修改的数据条数
    if (matched == 1 && modified == 1) {
        return true;
    }
    return false;
}
 
开发者ID:thankjava,项目名称:java-toolkit,代码行数:14,代码来源:MongoDriverManager.java

示例7: updateMany

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
@Override
public boolean updateMany(String docName, Document doc, Document docFilter) {
    UpdateResult upResult = baseUpdateMany(docName, doc, docFilter);
    if (upResult == null) {
        return false;
    }
    long matched = upResult.getMatchedCount();//匹配上的数据条数
    long modified = upResult.getModifiedCount();//已修改的数据条数
    if (matched > 0 && modified > 0) {
        return true;
    }
    return false;
}
 
开发者ID:thankjava,项目名称:java-toolkit,代码行数:14,代码来源:MongoDriverManager.java

示例8: putIfAbsent

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
@Override
public boolean putIfAbsent(String key, V value) {
  try {
    Bson query = Filters.eq(DrillMongoConstants.ID, key);
    Bson update = Updates.set(pKey, bytes(value));
    UpdateResult updateResult = collection.updateOne(query, update, new UpdateOptions().upsert(true));
    return updateResult.getModifiedCount() == 1;
  } catch (Exception e) {
    logger.error(e.getMessage(), e);
    throw new DrillRuntimeException(e.getMessage(), e);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:13,代码来源:MongoPersistentStore.java

示例9: restoreDocument

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
public static boolean restoreDocument(
        MongoCollection<BsonDocument> coll,
        Object documentId,
        BsonDocument shardKeys,
        BsonDocument data,
        Object etag,
        String etagLocation) {
    Objects.requireNonNull(coll);
    Objects.requireNonNull(documentId);
    Objects.requireNonNull(data);

    Bson query;

    if (etag == null) {
        query = eq("_id", documentId);
    } else {
        query = and(eq("_id", documentId), eq(
                etagLocation != null && !etagLocation.isEmpty() ?
                        etagLocation : "_etag", etag));
    }

    if (shardKeys != null) {
        query = and(query, shardKeys);
    }

    UpdateResult result = coll.replaceOne(query, data, U_NOT_UPSERT_OPS);

    if (result.isModifiedCountAvailable()) {
        return result.getModifiedCount() == 1;
    } else {
        return true;
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:34,代码来源:DAOUtils.java

示例10: upsertSync

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
public long upsertSync(MongoCollection<Document> collection, Bson filter, Document document) {
    UpdateResult result = collection.updateOne(filter, document, new UpdateOptions().upsert(true));
    return result.getUpsertedId() == null ? result.getModifiedCount() : 1;
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:5,代码来源:DatabaseConnection.java

示例11: upsertManySync

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
public long upsertManySync(MongoCollection<Document> collection, Bson filter, Document document) {
    UpdateResult result = collection.updateMany(filter, document, new UpdateOptions().upsert(true));
    return result.getUpsertedId() == null ? result.getModifiedCount() : 1;
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:5,代码来源:DatabaseConnection.java

示例12: updateSurveyFormType

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
public boolean updateSurveyFormType(String acronym, String surveyFormType) {
	UpdateResult updateOne = collection.updateOne(eq("surveyTemplate.identity.acronym", acronym.toUpperCase()),
			new Document("$set", new Document("surveyFormType", surveyFormType)));

	return updateOne.getModifiedCount() > 0 ? true : false;
}
 
开发者ID:ccem-dev,项目名称:otus-api,代码行数:7,代码来源:SurveyDao.java

示例13: updateTable

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
/**
 * update mongo collection.
 *
 * @param collection
 *            the collection name
 * @param q
 *            the update query
 * @param v
 *            the value
 * @param db
 *            the db
 * @return int of updated
 */
final public int updateTable(String collection, W q, V v, String db) {

	Document set = new Document();
	Document unset = new Document();

	// int len = v.size();
	for (String name : v.names()) {
		Object v1 = v.value(name);
		if (v1 == null) {
			unset.append(name, X.EMPTY);
		} else {
			set.append(name, v1);
		}
	}

	try {
		// log.debug("data=" + d);
		MongoCollection<Document> c = getCollection(db, collection);
		Document d = new Document();
		if (!set.isEmpty()) {
			d.append("$set", set);
		}
		if (!unset.isEmpty()) {
			d.append("$unset", unset);
		}
		UpdateResult r = c.updateMany(q.query(), d);

		if (log.isDebugEnabled())
			log.debug("updated collection=" + collection + ", query=" + q + ", d=" + set + ", n="
					+ r.getModifiedCount() + ",result=" + r);

		// r.getN();
		// r.getField("nModified");
		return (int) r.getModifiedCount();
	} catch (Exception e) {
		if (log.isErrorEnabled())
			log.error(e.getMessage(), e);
	}
	return 0;
}
 
开发者ID:giiwa,项目名称:giiwa,代码行数:54,代码来源:MongoHelper.java

示例14: update

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
@Override
public Boolean update (Map<String, Object> data, Boolean...notMuti) {
	// database,filter, data of inserting don't allow be null
	if (database == null || filters.get() == null || (mapDatas.get() == null && data == null)) {
		gc(); // clear
		return false;
	}
	
	// get current collection name
	String collectionNameForT = getCollectionName(collectionNames.get());
	// judge collection whether it's exited
	List<String> collections = getCollectionNames();
	// create index if the collection is not exited
	if (collections == null || collections.size() == 0 || collections.contains(collectionNameForT) == false) {
		gc(); // clear
		return false;
	}
	
	Map<String, Object> updateData = (data == null ? mapDatas.get() : data);
	
	Document document = new Document(updateData);
	
	// condition
	Bson filterBson = mapToBson(filters.get());
	
	// get update result
	UpdateResult result = null;
	
	try {
		// update many datas
		if (notMuti == null || notMuti.length == 0 || notMuti[0] == false) {
			result = database.getCollection(collectionNameForT).updateMany(filterBson, document);
		}
		else {
			result = database.getCollection(collectionNameForT).updateOne(filterBson, document);
		}
	} catch (Exception e) {
		
	}
	
	if (result == null
		|| result.getModifiedCount() == 0
		|| result.getMatchedCount()  == 0
	) {
		gc(); // clear
		return false;
	}
	
	gc(); // clear
	return true;
}
 
开发者ID:lolog,项目名称:mogodb-dao,代码行数:52,代码来源:MongoDaoImpl.java

示例15: updateOne

import com.mongodb.client.result.UpdateResult; //导入方法依赖的package包/类
/**
 * 更新符合条件的一条记录
 *
 * @param collectionName 集合名
 * @param query          查询条件
 * @param update         更新设置
 * @return
 */
public boolean updateOne(String collectionName, MongodbQuery query, MongodbUpdates update) {
    MongoCollection collection = sMongoDatabase.getCollection(collectionName);
    UpdateResult updateResult = collection.updateOne(query.getQuery(), update.getUpdates());
    return updateResult.getUpsertedId() != null ||
            (updateResult.getMatchedCount() > 0 && updateResult.getModifiedCount() > 0);
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:15,代码来源:MongodbDataAccess.java


注:本文中的com.mongodb.client.result.UpdateResult.getModifiedCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。