var mongoose = require('mongoose');
var Schema = mongoose.Schema;
mongoose.connect('mongodb://localhost/dbTest');
var arrayTestSchema = new Schema({
anArray: {
type: Array,
'default': []
}
});
mongoose.model('ArrayTest', arrayTestSchema);
ArrayTest = mongoose.model('ArrayTest');
var myTest = new ArrayTest();
console.log(arrayTestSchema.anArray);
mongoose.connection.close();
"์ ์๋์ง ์์"์ ํ์ํฉ๋๋ค.
์ ์ด๋ ๋ง์คํฐ์์๋ ์ด๊ฒ์ ์ ์๋ํฉ๋๋ค. MongooseArray๋ฅผ ๋ฐํํ๋ ๊ฒ์ ์ ์ธํ๊ณ ๋ ๋ค๋ฅธ ๋ง์ ๊ด๊ธฐ๋ก ๊ฐ๋ ์ฐจ ์์ต๋๋ค. :) ๊ฐ๋ฟ๋ง์ด ์๋๋๋ค.
์ด๋ค ๋ฒ์ ์ ์คํํ๊ณ ์์ต๋๊น?
var ๋ชฝ๊ตฌ์ค = ์๊ตฌ('๋ชฝ๊ตฌ์ค');
var ์คํค๋ง = ๋ชฝ๊ตฌ์ค.์คํค๋ง;
mongoose.connect('mongodb://localhost/dbTest');
var arrayTestSchema = ์๋ก์ด ์คํค๋ง({
Title: String,
Description: String,
Status: String
});
mongoose.model('ArrayTest', arrayTestSchema);
ArrayTest = ๋ชฝ๊ตฌ์ค.๋ชจ๋ธ('ArrayTest');
var myTest = ์๋ก์ด ArrayTest();
myTest.Title = 'ํ๋ก์ ํธ';
myTest.Description = 'mongodb ๋ฐ ๋
ธ๋ ์ฌ์ฉ';
myTest.Status = '์ด๋ฆผ';
console.log(myTest);
๋ชฝ๊ตฌ์ค.์ฐ๊ฒฐ.๋ซ๊ธฐ();
1.0.12, npm ๋ฒ์ ์ ์คํ ์ค์
๋๋ค.
์ด์ 1.0.12๊ฐ ๋ฆด๋ฆฌ์ค๋ ๊ฒ์ ๋ณด๋ ๋ง์คํฐ ๋ฒ์ ์ด์ด์ผ ํฉ๋๋ค.
ํ๋ผ๋ฅํฐ๋์ผ์ ์ง์ ํ๋ ค๋ ๊ฒ์ ์ดํดํ์ง ๋ง์ญ์์ค.
๋ฌธ์ ์ธ์คํด์ค์ ์ก์ธ์คํ์ง ์๊ธฐ ๋๋ฌธ์ ์คํจํฉ๋๋ค. ๋๋ ๋น์ ์ console.log๋ฅผ ์ฃผ์ ์ฒ๋ฆฌํ๊ณ ์ฌ๋ฐ๋ฅธ ๊ฒ์ผ๋ก ๋์ฒดํ์ต๋๋ค.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
mongoose.connect('mongodb://localhost/dbTest');
var arrayTestSchema = new Schema({
anArray: {
type: Array,
'default': []
}
});
mongoose.model('ArrayTest', arrayTestSchema);
ArrayTest = mongoose.model('ArrayTest');
var myTest = new ArrayTest();
// console.log(arrayTestSchema.anArray);
console.log(myTest.anArray);
mongoose.connection.close();
lol, ์์์ด, ์ด์ ๋ ๋์๊ฒ ๋์ ๋ ์ด์๋ค. ์ง์ ํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค =)
@bnoguchi ๋ฐฐ์ด ํญ๋ชฉ์ ์ ํ์ ์ด๋ป์ต๋๊น?
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ฌธ์ ์ธ์คํด์ค์ ์ก์ธ์คํ์ง ์๊ธฐ ๋๋ฌธ์ ์คํจํฉ๋๋ค. ๋๋ ๋น์ ์ console.log๋ฅผ ์ฃผ์ ์ฒ๋ฆฌํ๊ณ ์ฌ๋ฐ๋ฅธ ๊ฒ์ผ๋ก ๋์ฒดํ์ต๋๋ค.