How to stop insertion of Duplicate documents in a mongodb collection

Don’t use insert. Use update with upsert=true. Update will look for the document that matches your query, then it will modify the fields you want and then, you can tell it upsert:True if you want to insert if no document matches your query. db.collection.update( <query>, <update>, { upsert: <boolean>, multi: <boolean>, writeConcern: <document> } ) … Read more

Starting and populating a Postgres container in Docker

After a lot of fighting, I have found a solution 😉 For me was very useful a comment posted here: https://registry.hub.docker.com/_/postgres/ from “justfalter” Anyway, I have done in this way: # Dockerfile FROM postgres:9.4 RUN mkdir -p /tmp/psql_data/ COPY db/structure.sql /tmp/psql_data/ COPY scripts/init_docker_postgres.sh /docker-entrypoint-initdb.d/ db/structure.sql is a sql dump, useful to initialize the first tablespace. … Read more

What are horizontal and vertical partitions in database and what is the difference?

Not a complete answer to the question but it answers what is asked in the question title. So the general meaning of horizontal and vertical database partitioning is: Horizontal partitioning involves putting different rows into different tables. Perhaps customers with ZIP codes less than 50000 are stored in CustomersEast, while customers with ZIP codes greater … Read more

Difference between Stream Replication and logical replication

TL;DR: Logical replication sends row-by-row changes, physical replication sends disk block changes. Logical replication is better for some tasks, physical replication for others. Note that in PostgreSQL 12 (current at time of update) logical replication is stable and reliable, but quite limited. Use physical replication if you are asking this question. Streaming replication can be … Read more

Composite primary keys versus unique object ID field

Most of the commonly used engines (MS SQL Server, Oracle, DB2, MySQL, etc.) would not experience noticeable issues using a surrogate key system. Some may even experience a performance boost from the use of a surrogate, but performance issues are highly platform-specific. In general terms, the natural key (and by extension, composite key) verses surrogate … Read more

In what way does denormalization improve database performance?

Denormalization is generally used to either: Avoid a certain number of queries Remove some joins The basic idea of denormalization is that you’ll add redundant data, or group some, to be able to get those data more easily — at a smaller cost; which is better for performances. A quick examples? Consider a “Posts” and … Read more

Persist Security Info Property=true and Persist Security Info Property=false

Even if you set Persist Security Info=true OR Persist Security Info=false it won’t show a difference up front. The difference is happening in the background. When Persist Security Info=False, security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open … Read more

How to implement a db listener in Java

I have a solution for Oracle. You don’t need to create your own since now that Oracle bought Java it released a listener for it. As far as I know this does not use polling internally, instead notifications are pushed to the Java side (probably based on some trigger): public interface oracle.jdbc.dcn.DatabaseChangeListener extends java.util.EventListener { … Read more