添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐

I'm writing a web application using PHP/Symfony2/Doctrine2 and just finishing up the design of the Database. We have to import these objects (for ex. Projects, Vendors) into our database that come from different customers with variety of fields. Some customers have 2 fields in the project object and some have 20. So I was thinking about implementing them in MongoDB since it seems like a good use for it.

Symfony2 supports both ORM and ODM so that shouldn't be a problem, Now my question is how to ensure the integrity of the data in both databases. Because Objects in my MySQL db need to somehow be linked to the objects in the MongoDB for integrity issues.

Are there any better solutions out there? Any help/thoughts would be appreciated

Bulat implemented a Doctrine extension while we were at OpenSky for handling references between MongoDB documents and MySQL records, which is currently sitting in their (admittedly outdated) fork of the DoctrineExtensions project. You'll want to look at either the orm2odm_references or openskyfork branches. For this to be usable in your project, you'll probably want to port it over to a fresh fork of DoctrineExtensions, or simply incorporate the code into your application. Unfortunately, there is no documentation apart from the code itself.

Thankfully, there is also cookbook article on the Doctrine website that describes how to implement this from scratch. Basically, you rely on an event listener to replace your property with a reference (i.e. uninitialized Proxy object) from the other object manager and the natural behavior of Proxy objects to lazily load themselves takes care of the rest. Provided the event listener is a service, you can easily inject both the ORM and ODM object managers into it.

The only integrity guaranteed by this model is that you'll receive exceptions when trying to hydrate a bad reference, which is probably more than you'd get by simply storing an ID of the other database and querying manually.

I'm writing a web application using PHP/Symfony2/Doctrine2 and just finishing up the design of the Database. We have to import these objects (for ex. Projects, Vendors) into our database that come fro...
数据库集群具有数据备份、负载均衡等功能。比如 Mongodb 的复制集模式,Redis、 Mysql 的主从模式。这些模式均有它们各自的实现方式。有相同之处也有截然不容的处理方式。 Mongodb MongoDB 复制集模式数据同步主要分两类: Initial Sync 初始化同步,可理解为全量同步; Replication 拉取同步源 oplog 进行重放,可理解为增量同步。 在解释两类模式前先介绍 Mongodb 的 oplog 日志。在 Mongodb 中的 oplog 是一个固定长度(可设置)
分布式事务主要解决分布式一致性的问题。说到底就是数据的分布式操作导致仅依靠本地事务无法保证原的性。与单机版的事务不同的是,单机是把多个命令打包成一个统一处理,分布式事务是将多个机器上执行的命令打包成一个命令统一处理。 常见的分布式事务场景# 分布式事务其实就在我们身边,你一直在用,但是你却一直不注意它。 扣你账户的余额,增加别人账户余额,如果只扣了你的,别人没增加这是失败;如果没扣你的钱别人也增加了那银行的赔钱。 下订单/扣库存 电商系统中这是很常见的一个场景,用户下单成功了,店家没收到单
# mybatis数据源 spring.datasource.driver-class-name=com. mysql .cj.jdbc.Driver spring.datasource.url= spring.datasource.username= spring.datasource.password= # mongodb 数据源,主副 使用 逗号分隔 spring.data. mongodb .uri= mongodb ://192.168.10.150:27018,192.1
在 Spring Boot 中同时 使用 MySQL MongoDB 是非常容易的。首先,你需要在 pom.xml 文件中添加对 MySQL MongoDB 的依赖,如下所示: <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data- mongodb </artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> </dependencies> 然后,你需要在 application.properties 或者 application.yml 文件中配置 MySQL MongoDB 的连接信息,如下所示: spring.datasource.url=jdbc: mysql ://localhost:3306/test spring.datasource.username=root spring.datasource.password=password spring.data. mongodb .uri= mongodb ://localhost:27017/test 最后,你可以在你的代码中 使用 Spring Boot 的自动配置特性来注入并 使用 MySQL MongoDB 的数据源。例如,你可以在你的代码中注入 JdbcTemplate 来操作 MySQL ,或者注入 Mongo Template 来操作 MongoDB 。 @Autowired private JdbcTemplate jdbcTemplate; @Autowired private Mongo Template mongo Template; 这样,你就可以在同一个 Spring Boot 应用 中同时 使用 MySQL MongoDB 了。