Tech Tips

  1. プログラミング
  2. 2261 view

[mongoose][mongoDB]コレクションの指定方法

mongoose コレクション名 指定方法は
以下のソースの
lower case of collection_name+s
のところでコレクションを指定することである。 ここで気をつけなければならないことは、
小文字で最後に”s”をつける必要があることである。
そのため、mongoに作るコレクションの名前も同様のものでなければ
目的のコレクションに接続できない。
var EventRelation, db, mongoose;
mongoose = require('mongoose');
db = mongoose.connect('mongodb://localhost/db_name',
	function(err) {
		if (err) {
			console.log(err);
		} else {
			console.log('Connection Success!');
		}
	}
);

DBSchema = new mongoose.Schema({
  id                   : Number,
  update_time          : Date
});

exports.testDB = db.model('lower case of collection_name+s', DBSchema);

プログラミングの最近記事

  1. PlatformIO IDE for VSCode を使用して VSCode で Ardu…

  2. ROS Docker イメージで発生した GPG error の解消方法

  3. Streamlit で訪れた国を色づけした世界地図を作成できるアプリケーションを作成してみ…

  4. M5Stack Core2 for AWS – ESP32 IoT開発キットで…

  5. D3.js v7 で点・線・テキスト・ツールチップ・ズームを設定する方法

関連記事

PAGE TOP