Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove vs pull vs unset in mongoDB

Tags:

mongodb

I can remove a document or an element by remove, pull, unset.

What are the differences among those three?

Which one is safer way to remove in contemporary commanding issue?

and which one is fastest and efficient way to remove?

like image 204
jwchang Avatar asked Dec 12 '22 10:12

jwchang


1 Answers

remove removes a document from the collection. This is like an SQL DELETE.

$pull and $unset are update operations that change part of the document. They are similar to SQL UPDATE.

$pull removes an element from an array.

$unset removes the whole array (or any other field).

and which one is fastest and efficient way to remove?

Since they do completely different things, that is not a meaningful question.

like image 197
Thilo Avatar answered Jan 08 '23 01:01

Thilo