import mongoose from 'mongoose'
let db = mongoose.connection
db.on('error', console.error);
// CONNECTED TO MONGODB SERVER
console.log("Connected to mongod server");
mongoose.connect('mongodb://jsplays.iptime.org:27017/resource')
mongoose.connect('mongodb://username:password@host:port/database?options...');
let schema = mongoose.Schema
let testSchema = new schema({
date : { type : Date , default : Date.now}
String
Number
Date
Buffer
Boolean
Mixed
Objectid
Array
import mongoose from 'mongoose'
const schema = mongoose.Schema
const testSchema = new mongoose.schema ({
test : {type : Number , require : true , unique : true},
date : { type : Date , default : Date.now}
//콜렉션 이름을 지정하고싶으면 스키마 생성시 옵션으로 넣는다
// const todoSchema = new mongoose.Schema({..}, { collection: 'my-collection-name' });
//모델은 생성자이므로 인스턴스를 생성할수있음으로 속성이나 값을 추가하여 생성할수있다.
const Test = mongoose.model('Test' , testSchema)
const output = mongoose.model('Test' , testSchema)