本文整理汇总了Java中com.mongodb.client.model.Filters.eq方法的典型用法代码示例。如果您正苦于以下问题:Java Filters.eq方法的具体用法?Java Filters.eq怎么用?Java Filters.eq使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.client.model.Filters
的用法示例。
在下文中一共展示了Filters.eq方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getFilterBson
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
public static Bson getFilterBson(MatchOperator operator , String attributeName , Object value){
Bson filter = null;
switch(operator){
case GT :
filter=Filters.gt(attributeName, value);
break;
case LT :
filter=Filters.lt(attributeName, value);
break;
case GTE :
filter=Filters.gte(attributeName, value);
break;
case LTE :
filter=Filters.lte(attributeName, value);
break;
case EQ :
filter=Filters.eq(attributeName, value);
break;
case NE :
filter=Filters.ne(attributeName, value);
break;
default :
filter=Filters.eq(attributeName, value);
break;
}
return filter;
}
示例2: deleteById
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
/**
* 删除记录
*
* @param collectionName
* 表名
* @param mongoObj
* 记录
* @return
*/
public static boolean deleteById(String collectionName, MongoObj mongoObj) {
MongoCollection<Document> collection = getCollection(collectionName);
try {
Bson filter = Filters.eq(MongoConfig.MONGO_ID, mongoObj.getDocument().getObjectId(MongoConfig.MONGO_ID));
DeleteResult result = collection.deleteOne(filter);
if (result.getDeletedCount() == 1) {
return true;
} else {
return false;
}
} catch (Exception e) {
if (log != null) {
log.error("删除记录失败", e);
}
return false;
}
}
示例3: updateById
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
/**
* 修改记录
*
* @param collectionName
* 表名
* @param mongoObj
* 对象
* @return
*/
public static boolean updateById(String collectionName, MongoObj mongoObj) {
MongoCollection<Document> collection = getCollection(collectionName);
try {
Bson filter = Filters.eq(MongoConfig.MONGO_ID, mongoObj.getDocument().getObjectId(MongoConfig.MONGO_ID));
mongoObj.setDocument(null);
Document document = objectToDocument(mongoObj);
UpdateResult result = collection.updateOne(filter, new Document(MongoConfig.$SET, document));
if (result.getMatchedCount() == 1) {
return true;
} else {
return false;
}
} catch (Exception e) {
if (log != null) {
log.error("修改记录失败", e);
}
return false;
}
}
示例4: getChatById
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
public static ChatObj getChatById(String chatId, String chatGroupId) {
if (StringUtil.stringIsNull(chatId) || StringUtil.stringIsNull(chatGroupId)) {
return null;
}
Bson filter = Filters.eq(ChatObj.CHAT_ID, chatId);
List<ChatObj> list = MongodbManager.find(chatGroupId, filter, ChatObj.class, 0, 0);
if (list != null && list.size() != 0) {
return list.get(0);
} else {
return null;
}
}
示例5: deleteById
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
public static int deleteById(MongoCollection<Document> col, Object id) {
int count = 0;
Bson filter = Filters.eq("_id", id);
DeleteResult deleteResult = col.deleteOne(filter);
count = (int) deleteResult.getDeletedCount();
return count;
}
示例6: updateById
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
public static Document updateById(MongoCollection<Document> col, Object id, Document newDoc,
boolean repalce) {
Bson filter = Filters.eq("_id", id);
if (repalce)
col.replaceOne(filter, newDoc);
else
col.updateOne(filter, new Document("$set", newDoc));
return newDoc;
}
示例7: filter
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
private Bson filter(String field, String value) {
if (isBlank(value)) {
return null;
}
if (isRegex(value)) {
return Filters.regex(field, value.replaceAll("\\*", "\\.\\*"));
}
return Filters.eq(field, value);
}
示例8: getNodeDetails
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
public SyncNode getNodeDetails(SyncNode nodeMapper) {
Bson filter = Filters.eq(SyncAttrs.UUID, nodeMapper.getUUID());
logger.info("Getting node with filter " + filter);
return syncNodeMapping.findOneAndUpdate(filter, Updates.unset(SyncAttrs.FAILURE_TIME),
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
}
示例9: fromKey
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
/**
* Gets a DbFilter object from a key object
*
* @param c The class
* @param index The index of the key
* @param value The object of the key
* @return This
*/
public static DbFilter fromKey(Class<?> c, int index, Object value) {
return new DbFilter(Filters.eq(DataResolver.getKey(index, c), value));
}
示例10: eq
import com.mongodb.client.model.Filters; //导入方法依赖的package包/类
/**
* 等于
*
* @param name 字段名
* @param value 字段值
* @return
*/
public static MongodbQuery eq(String name, Object value) {
return new MongodbQuery(Filters.eq(name, value));
}