mongodb-update

Update multiple subdocument without exact sub document level condition

≯℡__Kan透↙ 提交于 2019-12-08 03:58:26
I have collection with the following document: { "_id" : ObjectId("56cbf9cd75de3ee9057b23c7"), "title" : "Abc", "comments" : [ { "_id" : "", "message" : "", "active" : 1, "status" : 1, }, { "_id" : "", "message" : "", "active" : 0, "status" : 1, }, { "_id" : "", "message" : "", "active" : 1, "status" : 1, } ], } { "_id" : ObjectId("553744ae75de3eb9128b4568"), "title" : "Jhon", "comments" : [ { "_id" : "", "message" : "", "active" : 1, "status" : 1, } ] } I need to update all status of comments as 0 where comments.active=1 . I tried to solve it as below, but only first record of the comments is

mongoDB : updating an objects using dot notation (multi-level object)

浪子不回头ぞ 提交于 2019-12-06 09:39:30
I have an object with the following form : { "_id": ObjectId("4fa43f4d1cf26a6a8952adf1"), "userId": "1", "facebookId": "1234", "groups": [{ "groupName": "testGroup", "members": [{ "memberFirstName": "userFirstName", "memberLastName": "userLastName", "memberDetails": { "userId": "1", "faceBookId": "1234" } }] }] } It's a collection that holds for each user - its groups, with each group containing the group members... So the "groups" key is an array (or list), and so is the "members" key. (each user could have multiple groups, each group has multiple group members). I'm having a hard time

MongoDB update multiple subdocuments with or query

半腔热情 提交于 2019-12-04 06:46:33
问题 I want to make an update query for multiple subdocuments at once. I will be setting all the subdocuments statuses to passive where they satisfy the condition I give on query. db.deduplications.update( { $and: [ { "_id": "189546D623FC69E3B693FDB679DBC76C" }, { "DeviceVersionPairs.DeviceId": ObjectId("5822d0606bfdcd6ec407d9b9") }, { "DeviceVersionPairs.CloudFolderId": ObjectId("5823110e6bfdd46ec4357582") }, { "DeviceVersionPairs.CloudFileId": ObjectId("582311168cd396223499942a") }, {

MongoDB concatenate strings from two fields into a third field

老子叫甜甜 提交于 2019-11-30 06:55:56
问题 How do I concatenate values from two fields and put it into a third one, the values are strings. I've tried this: db.collection.update({"_id" : { $exists : true }}, {$set: {column_2:{$add:['$column_4', '$column_3']}}}, false, true) doesn't seem to work though, throws not ok for storage . I've also tried this: db.collection.update({"_id" : { $exists : true }}, {$set: {column_2:{$add:['a', 'b']}}}, false, true) but even this shows the same error not ok for storage . I want to concatenate only

MongoDB $pull array 2 level

橙三吉。 提交于 2019-11-29 16:29:34
I'm trying to pull an element in an array with e two level deep complexity My document : > db.users.find({ mail : 'titi@toto.fr'}).pretty() { "_class" : "bean.User", "_id" : ObjectId("52f504bb2f9dd91186211537"), "commandes" : [ { "adresse" : "15 rue de la soif", "codePostal" : "29200", "idCommande" : 1, "montantTotal" : 0, "nom" : "TOTO", "prenom" : "tata", "ville" : "Brest", "voyagesSouscrits" : [ { "idVoyage" : "123", "duree" : 1, "nbPersonnes" : 0, "villeDepart" : "Nantes", "prixVoyage" : 999999 }, { "idVoyage" : "addVoyageSouscrit", "duree" : 1, "nbPersonnes" : 0, "villeDepart" : "Toulouse

MongoDB $pull array 2 level

前提是你 提交于 2019-11-28 09:45:18
问题 I'm trying to pull an element in an array with e two level deep complexity My document : > db.users.find({ mail : 'titi@toto.fr'}).pretty() { "_class" : "bean.User", "_id" : ObjectId("52f504bb2f9dd91186211537"), "commandes" : [ { "adresse" : "15 rue de la soif", "codePostal" : "29200", "idCommande" : 1, "montantTotal" : 0, "nom" : "TOTO", "prenom" : "tata", "ville" : "Brest", "voyagesSouscrits" : [ { "idVoyage" : "123", "duree" : 1, "nbPersonnes" : 0, "villeDepart" : "Nantes", "prixVoyage" :