mongodb update

64

db.people.updateMany(
   { age: { $gt: 25 } },
   { $set: { status: "C" } }
)
--SQL 
UPDATE people
SET status = "C"
WHERE age > 25
1	db.coll.update({"_id": 1}, {"year": 2016}) // WARNING! Replaces the entire document
2	db.coll.update({"_id": 1}, {$set: {"year": 2016, name: "Max"}})
3	db.coll.update({"_id": 1}, {$unset: {"year": 1}})
4	db.coll.update({"_id": 1}, {$rename: {"year": "date"} })
5	db.coll.update({"_id": 1}, {$inc: {"year": 5}})
6	db.coll.update({"_id": 1}, {$mul: {price: NumberDecimal("1.25"), qty: 2}})
7	db.coll.update({"_id": 1}, {$min: {"imdb": 5}})
8	db.coll.update({"_id": 1}, {$max: {"imdb": 8}})
9	db.coll.update({"_id": 1}, {$currentDate: {"lastModified": true}})
10	db.coll.update({"_id": 1}, {$currentDate: {"lastModified": {$type: "timestamp"}}})
11	
12	// Array
13	db.coll.update({"_id": 1}, {$push :{"array": 1}})
14	db.coll.update({"_id": 1}, {$pull :{"array": 1}})
15	db.coll.update({"_id": 1}, {$addToSet :{"array": 2}})
16	db.coll.update({"_id": 1}, {$pop: {"array": 1}})  // last element
17	db.coll.update({"_id": 1}, {$pop: {"array": -1}}) // first element
18	db.coll.update({"_id": 1}, {$pullAll: {"array" :[3, 4, 5]}})
19	db.coll.update({"_id": 1}, {$push: {scores: {$each: [90, 92, 85]}}})
20	db.coll.updateOne({"_id": 1, "grades": 80}, {$set: {"grades.$": 82}})
21	db.coll.updateMany({}, {$inc: {"grades.$[]": 10}})
22	db.coll.update({}, {$set: {"grades.$[element]": 100}}, {multi: true, arrayFilters: [{"element": {$gte: 100}}]})
23	
24	// Update many
25	db.coll.update({"year": 1999}, {$set: {"decade": "90's"}}, {"multi":true})
26	db.coll.updateMany({"year": 1999}, {$set: {"decade": "90's"}})
27	
28	// FindOneAndUpdate
29	db.coll.findOneAndUpdate({"name": "Max"}, {$inc: {"points": 5}}, {returnNewDocument: true})
30	
31	// Upsert
32	db.coll.update({"_id": 1}, {$set: {item: "apple"}, $setOnInsert: {defaultQty: 100}}, {upsert: true})
33	
34	// Replace
35	db.coll.replaceOne({"name": "Max"}, {"firstname": "Maxime", "surname": "Beugnet"})
36	
37	// Save
38	db.coll.save({"item": "book", "qty": 40})
39	
40	// Write concern
41	db.coll.update({}, {$set: {"x": 1}}, {"writeConcern": {"w": "majority", "wtimeout": 5000}})

Comments

Submit
0 Comments

More Questions

boolean in crandom number c ModuleNotFoundError: No module named cv2
check dns server in linuxread files in c how to get user input in c
print boolean value in clatex font sizes see if two strings are equal in C
how to download file in powershellprintf with bool invoke-webrequest download file
write in file in cmongodb delete all documents how to genrate a random number in C
how to print boolean in csleep in c programming install zoom on ubuntu
c concatenate stringstake array as input in c install gitk mac
remove element from np arrayprint an array in c C static libraries (creating object files)
exponentials in cC++ initalize int16_t value script hack blox fruti
pointer operatorcheck command line input is a number in c what is covert channel
sqlserver insert with set identity-usr-bin-env: python-r: No such file or directory linear search program in c
Uri-beecrowd problem no - 1099 solution in Cc addition The fscanf and fprintf functions
function that reverses the content of an array of integers.how to search in a file in c Couldnt create temporary file to work with
WARNING: QA Issue: bgslibrary-dev rdepends on libopencv-imgproc, but it isnt a build dependency, missing opencv in DEPENDS or PACKAGECONFIG [build-deps]reading arrays from stdin c add a item to cart woocomerce with quantity
Using PostgreSQL array to store many-to-many relationship using sqlalchemylistas enlazadas- linked lists binary sorting
c how to include variables of other c filec strcat uri-beecrowd problem no - 1133 solution in C