DB

MongoDB embedded documents

csohb 2023. 7. 16. 17:43
728x90
반응형

field의 값으로 다시 json nested data를 넣는 것을 embedded documents라고 한다. 

alcohol> db.alcoholData.updateMany({}, {$set: {feature: {color: "yellow", taste: "good"}}})
{
  acknowledged: true,
  insertedId: null,
  matchedCount: 2,
  modifiedCount: 2,
  upsertedCount: 0
}
alcohol> db.alcoholData.find().pretty()
[
  {
    _id: ObjectId("64b3a0234ad109d58f687358"),
    type: 'beer',
    marker: 'toDelete',
    taste: 'good',
    feature: { color: 'yellow', taste: 'good' }
  },
  {
    _id: ObjectId("64b3a02c4ad109d58f687359"),
    type: 'tequila',
    marker: 'toDelete',
    feature: { color: 'yellow', taste: 'good' }
  }
]

위의 예시는 feature라는 field의 값으로 nested json을 insert한 결과이다. 

 

728x90
반응형