๊ธฐ๋ฅ ์ ์์ฒญํ๊ฑฐ๋ ๋ฒ๊ทธ๋ฅผ๋ณด๊ณ ํ์๊ฒ ์ต๋๊น?
๊ณค์ถฉ
ํ์ฌ ํ๋์ ๋ฌด์์ ๋๊น?
์๋ ์คํฌ๋ฆฝํธ์์ ์์ ๋ฌธ์๋ฅผ ๊ฐ์ ธ์ฌ ๋ child
์ด {}
๋ก ๋์ ์ค์ง๋ง child2
์ด ์ฌ์ค์๋ ๋ถ๊ตฌํ๊ณ { field: 'test'}
๋ก ๋์ ์ค๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ChildSchema.field
์ select: false
์์ต๋๋ค.
๋๋ฒ๊ฑฐ๋ฅผ ๋ณผ ๋ child.field
์ ํ๋๊ณ child2.field
๋ ์ ํ๋์ง ์์ต๋๋ค.
const mongoose = require('mongoose');
mongoose.connect('mongodb://127.0.0.1/test');
const db = mongoose.connection;
db.once('open', async () => {
try {
const ChildSchema = new mongoose.Schema({
field: {
type: String,
select: false,
},
_id: false,
}, { id: false });
const ParentSchema = new mongoose.Schema({
child: ChildSchema,
child2: ChildSchema,
});
const Parent = mongoose.model('Parent', ParentSchema);
const ogParent = new Parent();
ogParent.child = { field: 'test' };
ogParent.child2 = { field: 'test' };
await ogParent.save();
const foundParent = await Parent.findById(ogParent._id).exec();
console.log(foundParent);
db.close();
} catch (e) {
console.log(e);
}
});
node.js, mongoose ๋ฐ MongoDB ๋ฒ์ ์ ์ธ๊ธํ์ญ์์ค.
4.11.8
์ ์ฒด ์ฌํ ์คํฌ๋ฆฝํธ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค. ๋ฒ๊ทธ์ฒ๋ผ ๋ณด์ ๋๋ค.
@wlingke ์๊ฒ 2017 โข ์ฌํด์ ๋ฒ ์คํธ ๋ชฝ๊ตฌ์ค ๋ฒ๊ทธ ํ์ธ๋๋ฅผ์ํ ๊ฐ์์ ๋ฐฐ์ง๋ฅผ ์ ๊ณตํฉ๋๋ค. ๐
@wlingke , 2014 ๋ ์ดํ ๋ชฝ๊ตฌ์ค์์ ๊ฐ์ฅ ๋ฏธ๋ฌํ ๋ฒ๊ทธ ์ฐพ๊ธฐ : rocket : : 1st_place_medal :
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@wlingke , 2014 ๋ ์ดํ ๋ชฝ๊ตฌ์ค์์ ๊ฐ์ฅ ๋ฏธ๋ฌํ ๋ฒ๊ทธ ์ฐพ๊ธฐ : rocket : : 1st_place_medal :