Is it better to use id for CURD operations with MongoDB?

For example, for update operation with MongoDB, there are several options like findOneAndUpdate, findByIdAndUpdate etc… Is it better to use findById than findOne? Any potential risks that lead people to use findById instead of findByOne and then pass in some filters?

Besides, I have seen the following syntax but don’t understand what the ‘…’ means.
const update = await User.updateOne(_.pick(user, ‘email’), { …req.body }, { new: true });
This is a patch request.

depends on the application as many will say. But _id is unique; so go for _id whenever possible when querying, such as findById, findIdAndUpdate, etc…

  1. the {} of {…req.body} is a must in mongoose;
  2. if req.body ={isPublish:true, price:66}, then {req.body}={{isPublish:true, price:66}};
  3. what mongoose really need is {isPublish:true, price:66}, so spread the object means removing the bracket here… so you dont need to type {isPublish:req.body.isPublish, price:req.body.price} one by one.
  4. same with array …[1,2,3] is the same as 1,2,3. so [1,…[1,2,3]] will become [1,1,2,3];
  5. {mama: 48, …{papa:50,son:20}} will become {mama: 48, papa:50, son:20};