MongoDBコネクタ
MongoDBコネクタは、MongoDBコレクションにJSONドキュメントを書き込みます。
コネクタタイプ: MongoWriter
{ "type": "MongoWriter", "config": { "endpoint": "mongodb://root:password@localhost:27017/", "database": "sensor_db", "collection": "measurements" }}設定パラメータ
Section titled “設定パラメータ”- endpoint: MongoDB接続文字列
- database: データベース名
- collection: コレクション名
接続文字列形式
Section titled “接続文字列形式”ローカルMongoDB
Section titled “ローカルMongoDB”mongodb://localhost:27017/mongodb://username:password@localhost:27017/MongoDB Atlas
Section titled “MongoDB Atlas”mongodb+srv://username:password@cluster.mongodb.net/オプション付き
Section titled “オプション付き”mongodb://localhost:27017/?authSource=admin&retryWrites=trueデータストレージ
Section titled “データストレージ”入力ペイロード:
{ "temperature": 25.5, "humidity": 60, "timestamp": 1234567890}MongoDBドキュメントとして保存:
{ "_id": ObjectId("..."), "temperature": 25.5, "humidity": 60, "timestamp": 1234567890}ユースケース:IoTデータストレージ
Section titled “ユースケース:IoTデータストレージ”{ "type": "MongoWriter", "config": { "endpoint": "mongodb://mongo.local:27017/", "database": "iot_platform", "collection": "sensor_readings" }}ベストプラクティス
Section titled “ベストプラクティス”- 意味のあるデータベースとコレクション名を使用
- ドキュメントにタイムスタンプを追加
- 頻繁にクエリされるフィールドにインデックスを使用
- コレクションサイズを監視してアーカイブを実装