mongoHelper 0.3.9 released, spring-data-mongodb enhanced toolkit

mongoHelper is an enhanced toolkit based on spring-data-mongodb, which simplifies CRUD operations and provides jpa-like database operations.

Traditional relational databases and the orm built around them have many difficult pain points in project development, and the emergence of documented databases such as mongodb perfectly solves many pain points of sql database in project development. After mongodb4.0 It supports the affairs and can be perfectly used in engineering projects. spring-data-mongodb has already encapsulated part of the operation of mongodb, but it is still not enough. The operation of Query and Criteria still has relatively large limitations, and for people who are used to sql operations and sql orm, its usage rules are still Slightly awkward. mongoHelper further encapsulates spring-data-mongodb, supplementing the features that mysql has but mongodb does not, such as field default values, making it easier to use, closer to the relational database orm library, and adding a lot of easy project management Function.

After using mongoHelper, it is possible to encapsulate the query paging statement similar to most mysql orm

public Page search(Page page, String word, Integer type) {
    CriteriaAndWrapper criteriaAndWrapper = new CriteriaAndWrapper();

	if (StrUtil.isNotEmpty(word)) {
		criteriaAndWrapper.and(new CriteriaOrWrapper().like(User::getName, word).like(User::getPhone, word));
	}
	if (type != null) {
		criteriaAndWrapper.eq(User::getType, type);
	}
	page = mongoHelper.findPage(criteriaAndWrapper, new SortBuilder(User::getCreatTime, Direction.DESC), page, User.class);

	return page;
}

Single table operation statement has become simple

  • Delete by id: mongoHelper.deleteById(String, Class<?>)
  • Delete by condition: mongoHelper.deleteByQuery(Criteria, Class<?>)
  • Query all: mongoHelper.findAll(Class)
  • Number of queries: mongoHelper.findCount(Class<?>)
  • Query by id: mongoHelper.findById(String, Class)
  • Query based on conditions: mongoHelper.findListByQuery(Criteria, Class<?>)
  • Query and page according to conditions: mongoHelper.findPage(Criteria, Page, Class<?>)
  • Insert: mongoHelper.insert(Object)
  • Insert or update: mongoHelper.insertOrUpdate(Object)
  • Update according to id: mongoHelper.updateById(Object)
  • Update all fields according to id: mongoHelper.updateAllColumnById(Object)
  • Update the first item according to the conditions: mongoHelper.updateFirst(Criteria, Update, Class<?>)
  • Update all items based on conditions: mongoHelper.updateMulti(Criteria, Update, Class<?>)

The printing of query statements is also formatted and standardized, and can be directly executed on the database client

db.admin.find({
    "$and": [
        {
            "name": {
                "$regex": "^.*ad.*$",
                "$options": "i"
            }
        }
    ]
}).projection({
    "name": 1
}).sort({
    "id": -1
});

This update content

1. Add the method of using Lambda to get the field name

2. Add support for springBoot 2.3.0

3. Fix some bugs

Code address:  https://gitee.com/cym1102/mongoHelper

Guess you like

Origin www.oschina.net/news/120882/mongohelper-0-3-9-released