Copying records in collection within collection but with different value

Hello,

So I can’t find an answer for this anywhere, but I want to duplicate some records in a collection but with a different value

For example, lets say I have the following records

KEY: 1
LOCATION: 500

KEY: 2
LOCATION: 500

KEY: 3
LOCATION: 500

I’d like to copy these 3 records to look like this:

KEY: 1
LOCATION: 600

KEY: 2
LOCATION: 600

KEY: 3
LOCATION: 600

Resulting in 6 records

Surely this must be something easy, I just can’t figure it out.

I think I figured it out:

db.tblTrainingCodeCategories.find({}).forEach(function(doc){ delete doc[’_id’]; doc.LOCATION = 2309; db.tblTrainingCodeCategories.insert(doc); } )

This essentially does it…

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.