MongoDB中orm框架的注意事项有哪些

发布时间:2021-06-21 10:41:33 作者:小新
来源:亿速云 阅读:118

小编给大家分享一下MongoDB中orm框架的注意事项有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

首先spring自带了mongodb的orm,spring data mongodb,但是这个框架非常难用,最令人抓狂的是每个文档都要带一个 _class 字段,因为这个是string的,所以占用不少空间,而且去除也比较麻烦。故而使用 zfoo orm 框架

Ⅰ. 简介

基于MongoDB的orm框架,提供POJO对象和MongoDB数据库之间的映射

Ⅱ. 注意事项

Ⅲ. 使用方法

1. IAccessor接口,为数据访问接口

OrmContext.getAccessor().insert(obj)
OrmContext.getAccessor().delete(obj);
OrmContext.getAccessor().update(obj);

2. IQuery接口,为数据复杂查询接口

3. 缓存使用方法

例如有下列配置

<orm:config id="config" entity-package="com.zfoo.orm.**.entity">

    <orm:host database="test" user="" password="">
        <orm:address name="server0" url="127.0.0.1:27017"/>
    </orm:host>

    <!-- 缓存策略 -->
    <orm:caches>
        <orm:cache strategy="ten" size="10" expire-millisecond="600000"/>
        <orm:cache strategy="hundred" size="100" expire-millisecond="600000"/>
        <orm:cache strategy="thousand" size="1000" expire-millisecond="600000"/>
        <orm:cache strategy="threeThousand" size="3000" expire-millisecond="600000"/>
        <orm:cache strategy="tenThousand" size="10000" expire-millisecond="600000"/>
    </orm:caches>

    <!-- 持久化策略 -->
    <orm:persisters>
            <orm:persister strategy="cronDefault" type="cron" config="0,30 * * * * ?"/>
            <orm:persister strategy="cron3s" type="cron" config="0/3 * * * * ?"/>
            <orm:persister strategy="cron15s" type="cron" config="0/15 * * * * ?"/>
            <orm:persister strategy="cron30s" type="cron" config="0/30 * * * * ?"/>
            <orm:persister strategy="cron1m" type="cron" config="0 0/30 * * * ?"/>
            <orm:persister strategy="time30s" type="time" config="30000"/>
        </orm:persisters>
</orm:config>

有下列注解

@EntityCaches(cacheStrategy = "tenThousand", persister = @Persister("time30s"))
public class UserEntity implements IEntity<Long> {
}

Ⅳ. 教程

test下中包含了所有增删改查的教程,运行之前请先安装MongoDB

以上是“MongoDB中orm框架的注意事项有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. mongodb的应用场景、注意事项
  2. MongoDB日常使用的技巧与注意事项有哪些

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mongodb orm框架

上一篇:php把时间戳转换为日期格式的方法

下一篇:php判断是数组还是对象的方法有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》