本文整理匯總了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));
}