-
-
Save divjotarora/992099cef9e2014582fcd5698521f2e3 to your computer and use it in GitHub Desktop.
Update existing field to value of another field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conn = new Mongo() | |
db = conn.getDB('test') | |
coll = db.coll | |
coll.drop() | |
try { | |
print(conn.getDB('admin').runCommand({buildInfo: 1})['version']) | |
coll.insert({ | |
id: 123, | |
PreviousRecord: 'old', | |
CurrentRecord: 'new', | |
}) | |
print('before updating') | |
printjson(coll.findOne()) | |
coll.update({id: 123}, {'$set': {'PreviousRecord': '$CurrentRecord'}}) | |
print('after updating') | |
printjson(coll.findOne()) | |
} catch(e) { | |
printjson(e) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment