1.

In a 3 Member Replica set if the secondary is lagging behind what can be checked for same?

Answer»

The $addToSet operator should be used with the $each modifier for this. The $each modifier allows the $addToSet operator to add multiple values to the array field.

Example, start ups are tagged as per the technology skill that they excel in

{ _id: 5, name: "XYZ Technology", SKILLS: [ "BIG DATA", "AI", “Cloud” ] } 

Now the start up needs to be updated with additional skills

db.startups.update(   { _id: 5 },          { $addToSet: { skills: { $each: [ "MACHINE Learning", "RPA" ] } } }       )

The resultant document after update()

{ _id: 5, name: "XYZ Technology", skills: [ "Big Data", "AI", “Cloud”,  "Machine Learning", "RPA"] }

Note: There is no particular ORDERING of elements in the modified set, $addToSet does not guarantee that. Duplicate items will not be added.   



Discussion

No Comment Found