Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

mongodb - Using updateMany() in updating multiple documents

I have trouble in updating all my documents in MongoDB. Update is the easiest I could do but I still wanted options on how to update them all without using update all over again. as you can see in the picture only one document is modified not all of them. should I use foreach? and If yes, how to do it? I apologize in advance since I'm only a beginner, still learning the ropes of MongoDB.

enter image description here

Here is my code:

db.employees.updateMany(`

{id: 1},{$push: {"contact": {"email": "steve.badiola.gov.ph", "phone": "+1 1234567"}}},

{id: 2},{$push: {"contact": {"email": "jamir.garcia.gov.ph", "phone": "+2 1234567"}}},

{id: 3},{$push: {"contact": {"email": "reg.rubio.gov.ph", "phone": "+3 1234567"}}},

{id: 4},{$push: {"contact": {"email": "ian.tayao.gov.ph", "phone": "+4 1234567"}}})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...