$pull
을 활용하여 배열 안에 특정 레코드만 삭제 할 수 있다.
before
1
2
3
4
5
6
7
8
9
{ _id: ObjectId("62aad6a97a158813a86ce9be"),
signedBy:
[ { _id: ObjectId("62aad6c47a158813a86ce9f0"),
user: '6156a3c9c7f00c0d4ace4744',
signedTime: 2022-06-16T07:07:48.742Z },
{ _id: ObjectId("62aad6c47a158813a86ce9f0"),
user: '6156a3c9c7f00c0d4ace4745',
signedTime: 2022-06-16T07:08:49.242Z, } ]
}
update
1
$ db.documents.updateOne({'_id' : ObjectId('62aad6a97a158813a86ce9be')}, {$pull: {signedBy: {'user': '6156a3c9c7f00c0d4ace4744'} }} )
after
1
2
3
4
5
6
{ _id: ObjectId("62aad6a97a158813a86ce9be"),
signedBy:
[ { _id: ObjectId("62aad6c47a158813a86ce9f0"),
user: '6156a3c9c7f00c0d4ace4745',
signedTime: 2022-06-16T07:08:49.242Z, } ]
}