はじめに

システム開発でよく使われるデータベースといえば、RDB(リレーショナルデータベース)が定番です。私のチームでも長らく、Oracle や MySQL などの RDB を利用してきましたが、ある新規APIの開発で MongoDB を採用してみたところ、思っていた以上に開発がスムーズになりました。

この記事では、MongoDB を Java + Spring Boot で使用してみて感じた3つのメリットを、実際の実装例を交えて紹介します。

MongoDB の特徴

MongoDB はドキュメント指向の NoSQL データベースであり、RDB と比べて非常に緩い設計になっているのが特徴です。RDBと違いを感じるのは、例えば以下のような点です。

  • 構造化オブジェクト(JSONのようなもの)を丸ごと保存できる
  • 格納するオブジェクトの仕様を厳密に決めておく必要が無い(カラム定義などは不要)
  • コレクション(RDBでいうところのテーブル)に追加しようとしたときに、コレクションが無ければ自動的に作成される。データベースが無かった場合は、データベースも自動的に作成される

プログラムから 何でも入る入れ物 的な感覚で、簡単に使えるのが特徴です。

簡単に始められる MongoDB

MongoDB の準備

MongoDB はローカルにインストールして起動します。インストール手順は割愛しますが、Dockerイメージ を使うか、公式サイトからダウンロードしてインストールすることになります。

前述した通り、データベースやコレクションを用意する必要は無いのですが、ユーザだけは用意しておく必要があります。インストールした後、以下のコマンドを MongoDB Shell などで実行します。

use admin
db.createUser({
  user: "appuser",
  pwd:  "secret",
  roles: [ { role: "readWrite", db: "sampledb" } ]
})

Spring Boot の設定

Spring Boot では、spring-boot-starter-data-mongodb を依存関係に追加するだけで、 MongoDB を簡単に利用できます。Maven の場合は以下を pom.xml に追加します。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

接続設定は Spring Boot の application.yml に以下のように記述します。

spring:
  data:
    mongodb:
      host: localhost
      port: 27017
      database: sampledb
      username: appuser
      password: secret
      auto-index-creation: true

auto-index-creation は、後に説明する @Indexed でインデックスを作る機能を有効にするための設定です。

エンティティ

@Document(collection = "login_history")
public class LoginHistory {
    @Id
    private String id;

    @Indexed
    private String userId;

    @Indexed(expireAfter = "30d") // 30日で自動削除
    private LocalDateTime createdAt;
}

エンティティクラスに付けている @Document アノテーションで、保存するコレクション名を指定しています。

@Id をつけたフィールドは _id という特殊なフィールドにマッピングされます。これはコレクション内でドキュメントを一意に識別するための値で、RDBでいうところの主キーに相当する役割を持ちます。

@Indexed は項目にインデックスを作成するアノテーションです。RDBのインデックスと同様で、この項目による検索を高速に行えるようになります。

expireAfter をつけると、 TTL(Time To Live)インデックス という特殊なインデックスが作成されます。これは、設定した期間を過ぎると、MongoDBが自動的にレコードを削除してくれる機能です。この例では createdAt から30日以上経過している場合に削除対象となります。

リポジトリ

public interface LoginHistoryRepository extends MongoRepository<LoginHistory, String> {
    List<LoginHistory> findByUserId(String userId);
}

あとはこのリポジトリをDIして、簡単に読み書きができます。

// 保存
loginHistory.setId("a001");
loginHistory.setUserId("sampleUser");
loginHistory.setCreatedAt(java.time.LocalDateTime.now());
loginHistoryRepository.save(loginHistory);

// IDで取得
Optional<LoginHistory> h1 = loginHistoryRepository.findById("a001");

// ユーザIDで取得
List<LoginHistory> histories = loginHistoryRepository.findByUserId("sampleUser");

このようなコードで最初のレコードを save すると、MongoDB 側には自動的に login_history コレクションが作成され、userIdcreatedAt にインデックスが付与されます。

実感した MongoDB の3つのメリット

1. DDL作成や実行が不要

前述した通り、MongoDB はコレクションが無くても自動的に作ってくれますし、スキーマを決めておく必要もありません。

そのため、Spring のプログラムから何かを保存したいと思ったときに、エンティティとリポジトリさえ用意すれば、すぐに保存することができます。

これによって、開発者がプログラムとDBを同時に扱えるようになり、RDBと比べて開発の自由度とスピードが上がりました。

2. TTLインデックスによる自動削除が便利

ログやセッション情報など、「一定期間で削除してよいデータ」は多く存在します。RDBでは古いデータを削除するためにバッチ処理を用意し、スケジュール実行・監視を行うのが一般的です。

MongoDBでは、前述したTTLインデックスを設定するだけで、MongoDBが自動的に期限切れのデータを削除してくれるため、削除バッチを作る必要がなくなりました。

3. データ構造が柔軟で変更に強い

正規化せずにデータを格納するため、RDBでは複数テーブルに分けてJOINしていたデータも1ドキュメントにまとめて保持できます。

そのため、データ構造が変更になっても、RDBと比べて影響が少なく、変更に強いと感じました。

導入して感じたこと

MongoDB はとても使いやすくて便利なデータベースですが、必ずしもRDBよりも優れているというわけではありません。向き不向きはあります。

具体的には、やはり正規化されていないので、複雑な結合クエリや集計は書きづらいです。複雑な検索が必要なデータには、RDBのほうが向いていると思います。

一方で、複雑な集計を必要としないデータであれば、非常に使いやすく、用途によっては良い選択肢になると感じました。

まとめ

MongoDB を Java/Spring 環境で使ってみて感じたメリットは、以下の3点でした。

  • DDL作成や実行が不要
  • TTLインデックスによる自動削除が便利
  • データ構造が柔軟で変更に強い

一昔前は、データベースと言えばRDBでしたが、最近は MongoDB のようなドキュメント指向DBを始めとして、様々な種類のデータベースが登場しています。そして、それらが現場で使われ始めているとも感じています。

データベースには向き不向きがあります。特定の技術に固執するのではなく、様々な種類のデータベースの特徴を比較検討し、最適なものを選択することが、これからの開発には求められていくと思います。

This means you’ll be getting the exact same experience since the a real currency blackjack user, however, without having any chance to winnings or generate losses. This short article make suggestions through the finest on the internet blackjack Uk gambling enterprises, examining the varied playing choices and you may crucial have to search for. If or not you’lso are not used to the game or a seasoned athlete, the newest understanding offered will help you build told alternatives for an enthusiastic memorable alive black-jack feel.

The initial bargain is crucial, while the a couple notes you will get usually guide your own proper decisions. The brand new agent’s give also offers an idea regarding their visible credit, helping the next move. Think about, responsible gambling advances enjoyment, flipping for every hand to the a great adventure in the wonderful world of United kingdom online blackjack. Super Black-jack raises arbitrary honor multipliers to the specific cards.

Exactly why are Bitcoin Gambling enterprise Websites A lot better than Conventional Gambling enterprises?

The history of black-jack schedules a long time before when people started playing they on line. Due to this, we feel all the genuine fan should know more info on how it all become and how the video game changed usually. From the very second section, we’ll make you historically founded details about the newest origins of black-jack and the significant situations you to resulted in the video game are while the we know it now. Some of the finest on line position sites also will let you sort from the creator to locate specific games easily.

Such as, for those who have some, you can broke up such on the a few separate hands by the placing an a lot more bet, comparable to the initial choice. Doubling off along with concerns placing an extra wager then you is dealt another cards. If the dealer’s right up card try an enthusiastic adept, you will additionally be provided with the option to place an insurance coverage bet. The best on line blackjack site is safe and you can safer and includes a substantial number of blackjack game versions. The best blackjack webpages comes with the incentives for the card game, along with punctual, hassle-totally free winnings. You might winnings in the black-jack by getting nearer to 21 than simply the new broker instead of splitting.

A person protects an earn by the surpassing the newest dealer’s overall rather than surpassing the newest crucial 21-point tolerance. At the same time, in case your broker is preferable to 21 things, the gamer wins despite their particular hands’s overall. In the video game training, people have the opportunity to manage numerous strategic tips, and make for every round enjoyable and you can active. Any advice for the fresh game play usually looks inside the a different range one to near the top of your screen or even in pop-upwards windows that is right above the playing urban area. Usually, the game favours players which can be as to the reasons profitable involved is pretty effortless.

In that way, you’re laying down a powerful base to own an advisable on the web playing experience. We’lso are usually reviewing casinos on the internet and you will searching for an educated offers to possess You.S. The following is a list of Casinos that may boost your money for individuals who’lso are looking for taking a chair and watching a round of real-currency Blackjack. Playing blackjack free of charge are fun, your won’t be able to winnings real cash away from totally free game. For those who’d enjoy playing for real currency, here are some our very own list of the major black-jack casinos online. However unclear why you need to is to try out on line blackjack to own real money?

That it added bonus, along with the program’s member-friendly interface, helps it be an interesting choice for each other the new and knowledgeable participants. In this article, you’ll discover the better programs to play on in 2025, understand the most recent legal landscape, and have tips on choosing the right gambling establishment for you. Card counting is actually a method to overseeing cards one to have been used within the earlier video game rounds to achieve a statistical advantage over the newest local casino.

Evaluate Blackjack Online game

It may be daunting to find through the of a lot internet sites so you can find the right you to have fun with, and that’s as to the reasons our pros have inked the hard area. Tx casinos provide a variety of percentage solutions to ensure that players can simply manage their funds. Preferred deposit steps were credit/debit notes, e-purses such PayPal and you may Neteller, and prepaid notes such as Gamble+. This type of options give freedom and comfort, allowing players to search for the method you to is best suited for their needs. As well, land-centered casinos render a personal atmosphere you to online platforms do not simulate. The new excitement out of a bustling gambling enterprise floor, the brand new tunes of slot machines, plus the camaraderie one of professionals perform an enthusiastic immersive experience a large number of find irreplaceable.

These types of systems give many different game and you will promotions, getting a thrilling experience without the need for real money wagers. Trying out individuals alive blackjack game differences is retain the novelty and you can adventure of the gaming sense. Per online game type offers book regulations, side wagers, and features which can add a different amount of adventure to help you the game play.

✅ Special Incentives

From the bright world of online black-jack in britain, choosing the best live blackjack gambling establishment can also be it really is lift up your playing feel. To be sure a secure and you will seamless sense, prioritize gambling enterprises offering top payment choices such as PayPal, Visa, Skrill, and you can Mastercard. For those who’re also picking out the finest on line black-jack expertise in the uk, this type of better-rated gambling enterprises provide unequaled real time blackjack games you to definitely serve all of the people.

The history of real money Black-jack

Let’s view probably the most preferred deposit possibilities you can utilize to try out blackjack the real deal currency on the web. You could gamble all these non-live black-jack online game used form if you would like extent something out before you could play for a real income. Another important factor is its commitment to pro protection and you will fairness. Rolletto try subscribed and you will controlled from the Curaçao Gaming Panel, ensuring clear, safe gameplay. Simultaneously, they boasts an intuitive program and you will a seamless cellular betting feel, so it’s simple for players to love blackjack to the-the-wade. Blackjack has the better odds of effective, that have a house side of lower than 1% at the most casinos.

While the notes is worked, the point tally begins, and you may people can get decide to mark additional cards if they understand a chance to enhance their hand. The newest central objective of your own online game is to avoid exceeding 21 points, because the performing this causes an automatic losings. Black-jack remains probably one of the most well-known and you will satisfying casino games, but as long as played to the right system. Inside guide, we assessed 120 online casinos and known the big ten you to offer the greatest total black-jack experience in 2025. We secure everything from video game alternatives and you may rule equity to help you commission rates, mobile performance, and extra high quality.

Practical Enjoy’s Alive Black-jack Azure

It’s a sanctuary where variety fits quality, and you may in which the passion for blackjack is actually matched up simply by the casino’s commitment to delivering an exceptional betting ecosystem. Embrace the entire process of mining, and you can allow the unique features of for each video game allow you to their blackjack haven. Talk about all of the alternatives, and choose the one that aligns together with your needs, making certain that their interest remains for the game and not on the the protection of the money. El Royale’s live game perform a social ecosystem one entices and entertains, appealing you to definitely partake in a world where per hand dealt try a wash that have destiny. If you struck and are dealt a great 7, you’ll has a get of 22, definition you may have moved breasts. The elevated exposure with tough hands would be the fact supposed breasts is actually many of one’s game with this combinations.

Dolphin’s Pearl Deluxe takes on to the a 3 times 5 grid one to includes ten adjustable paylines. Lines was adjusted from one to ten meaning restricted will cost you to experience for each spin can begin in one cent for each and every spin. Once you’lso are there are numerous honours as claimed in this game, here aren’t people jackpots. Understand more about which position to see if they’s well worth to try out, read this Whales Pearl slot comment. Hence, do not spend time, work with the fresh construction and relish the travel.

It’s and high as it’s internet browser centered, definition it functions on the Mac computer and you may Window without the need to install any additional app. Although not, it must be listed one Whales Pearl is actually a leading-volatility identity, thus be mindful of the money even when to ensure your don’t remove excess amount chasing the new jackpot. Totally free top-notch instructional programs for online casino personnel geared towards industry guidelines, improving athlete experience, and reasonable way of gaming.

Ideas on how to Gamble and you will Win from the Slots

At the the key, Dolphin’s Pearl Luxury are a good 5-reel slot that have up to ten variable paylines. The video game are superbly built with symbols symbolizing the company the newest marine environment. The brand new pearl oyster, acting as the brand new spread symbol, unlocks the fresh sought after free revolves function, boosting probability of generous pros ( per cent 100 percent free spins, multiplier x3). Once you have fun with the server Whales, you will get access to the main benefit video game for many who enjoy for real currency.

The new video slot brings an exciting sense with their pleasant theme. Greentubes complete Go back, to Pro (RTP) speed ensures an opportunity to victory, providing in order to one another newbies and you may educated players. The new revolves can be worth a total of A great$20 and can become triggered from the advertisements page of the local casino.

100 percent free Novomatic Ports

Secret has are an advantage bullet, 15 totally free spins, and you may 3x multipliers, rendering it identity a persuasive choice for enjoyable. Such bonuses provide possible profit and you will sign up for the fresh position’s popularity. Launches presenting such provides often attract more gamblers while they boost overall playing. Their no down load HTML5 version holds the have and you will assurances easier access.

The next symbol is the Insane dolphin icon which can play while the any icon but the new Spread out and you may contributes a two minutes multiplier to virtually any profitable lines that will be integrated. After you winnings that have around three or more Scatters, you additionally receive fifteen totally free revolves having an excellent 3 x multiplier for the profits through the the individuals 100 percent free revolves. RTP is key shape to possess harbors, working reverse the house border and you may demonstrating the possibility payoff in order to people. Is the newest Dolphins Pearl totally free enjoy video game, and you will retrigger the fresh totally free spins extra and revel in a good 2x multiplier. In the end, you forfeit a dynamic additional for individuals who consult a detachment before showing up in playthrough address.

It needs to be noted your offered level of lines inside the device leads to more regular density away from gains. You still need to search for the measurements of the new bet (the fresh option Bet); the higher can be your wager, more you could potentially win. In order to gamble Whales Pearl Luxury Free Slot on the web, you need to investigate purchase out of costs. Click on the Let key to see the cost specifics of all of the you’ll be able to options for victory from the video game. Dolphin is also exchange one icon regarding the game (Nuts symbol) but the fresh scatter.

We’ve had you covered with all you need to know betting firm bonus conditions for instance the after the. It is important to know very well what you’re joining while you searching for a betting casino on line bonus. Listed below are an informed tips to keep an eye on as the you look around for your forthcoming gambling enterprise added bonus. All the local casino offers readily available is actually varied and you can all the you to will benefit you in different ways. For many who’lso are a black-jack pro, you’ll see loads of options to select, and you can Eu and you can Antique names.

Real cash Slots

I have a good kind of better $10 deposit online casino websites you can test. The video game’s reels are prepared against bright aquatic colors and possess icons including oyster, tropical fish, dolphin, seahorse, flatfish, and you can lobster. Oysters and you will whales is actually large-paying signs if you are flatfish, seahorses, exotic seafood, and you can lobster is the reduced-paying signs. Whales pearl on line slot features an aquatic motif who may have a keen attractive history voice one provides people happy. Water vegetation can be seen on the history, which is perfect for the fresh motif.

Gamers are on the fresh look for cost under water to play Whales Pearl Deluxe variation. Because there are too many bells and whistles of numerous, anyone look at this video game one of the best on line slots around right now, and another one Novomatic can merely take a lot of pride inside the. Will you be constantly choosing the next trouble with higher candidates for achievement and you may need to win over almost every other gamers in the all of our slots? Then take part in one of the of several leaderboard video game otherwise unique campaigns inside our Casino. Huge Twist wins and you will a fantastic escapades in the best game for example Dolphinʼs Pearl deluxe watch for your that can help you stay on the foot some time and go out again.

Making a large earn you will want to house the newest slightly uncommon free revolves bonus. RTP, or Return to Player, are a portion that shows how much a slot is expected to expend returning to players more years. It’s calculated considering many if not huge amounts of spins, so that the per cent is actually accurate ultimately, maybe not in one example. Dolphin’s Pearl Luxury is an up-to-date type of the brand new Dolphin’s Pearl position in just a great payline splitting up the original and the new follow up. It 5 reel and you can ten payline position is actually a beautiful presentation that will enchant your featuring its appearance and its particular gameplay the exact same.

Should you, you can even gamble Dolphin’s Pearl as a result of an entirely optimized cellular version. Because the Dolphin’s Pearl is actually an excellent 2008 position online game, you simply can’t inquire about too much with regards to image, sounds, and you may animated graphics. Instructions on exactly how to reset your code have been delivered to your in the an email. We’ve in addition to had numerous Safer Gambling points available within the acquisition to ensure the day on site remains enjoyable and practical. The newest password should be 8 emails if not extended and may also have one or more uppercase and lowercase character.

Is our very own the newest 100 percent free position competitions

The new strike regularity speed on the The newest Dolphin’s Pearl Luxury position is twenty-five%, and therefore an earn requires put, typically, all 2nd spin. And make sure you have got a look through OLBG’s level of status video game analysis as well as 100 percent free ports so you can enjoy. A premier alternatives as well as increases the limitation commission naturally combinations. Whenever only wilds are present, they generate winning combos in the productive paylines. But not, wilds increase winnings better and in case along with most other signs. If you’re looking to possess an under water adventure in which huge progress is at express, the newest Dolphin’s Pearl Deluxe condition is better!

Learn how we helped 100 top brands gain success