0

I want to remove object to use mongodb.

First find ID and second remove only AAA field.

I tried it to use findOneAndDelete function. but It wrong worked.

It worked Find(OK) and Delete query(false).

I want to keep other filed and remove target filed(AAA).

please share your idea.

below example code.

{ id: 6319, AAA : Object , BBB : Object , CCC : Object },

result = await User.findOneAndDelete({id : 6319 },{ projection : { AAA : Object } });
Ravi
  • 424
  • 3
  • 13
  • possible duplicate: https://stackoverflow.com/questions/6851933/how-to-remove-a-field-completely-from-a-mongodb-document – Nemer Aug 25 '19 at 14:53
  • Thank you for your reply. I resolve it. result = await User.findOneAndUpdate({id : 6319 },{ $unset: { [AAA] : 1 } }); – 휘바골드 Aug 25 '19 at 15:25

1 Answers1

0

Please try using $unset to remove the field

Dexter
  • 831
  • 8
  • 17