Categories: Uncategorized

[mongoose][mongoDB]How to select collection

Select collection at “lower case of collection_name+s” part below. Note that you have to add “s” at last end use lower case of collection name.
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);
zuqqhi2