Dan_Burt
(Dan Burt)
May 17, 2021, 12:27pm
1
The following code does not seem to update the 2 documents I have in this collection:
db.playerTest.updateMany({},{$set: {"clubs": [[ { "clubId": ObjectId("6076030465508936f00e086c")}, {"name": "Augusta National Golf Club"}, {"nickName": "Augusta"}, {"logoPath": "augusta.png"}]]}})
It needs to be an Array
of Objects
It returns the following output, which suggests the syntax is good, but is not being applied:
{ acknowledged: true,
insertedId: null,
matchedCount: 0,
modifiedCount: 0,
upsertedCount: 0 }
steevej
(Steeve Juneau)
May 17, 2021, 12:41pm
2
Dan_Burt:
db.playerTest.updateMany({},{$set: {“clubs”: [[ { “clubId”: ObjectId(“6076030465508936f00e086c”)}, {“name”: “Augusta National Golf Club”}, {“nickName”: “Augusta”}, {“logoPath”: “augusta.png”}]]}})
With the same code I get:
> db.playerTest.find()
{ "_id" : 0 }
{ "_id" : 1 }
> db.playerTest.updateMany({},{$set: {"clubs": [[ { "clubId": ObjectId("6076030465508936f00e086c")}, {"name": "Augusta National Golf Club"}, {"nickName": "Augusta"}, {"logoPath": "augusta.png"}]]}})
{ "acknowledged" : true, "matchedCount" : 2, "modifiedCount" : 2 }
> db.playerTest.find()
{ "_id" : 0, "clubs" : [ [ { "clubId" : ObjectId("6076030465508936f00e086c") }, { "name" : "Augusta National Golf Club" }, { "nickName" : "Augusta" }, { "logoPath" : "augusta.png" } ] ] }
{ "_id" : 1, "clubs" : [ [ { "clubId" : ObjectId("6076030465508936f00e086c") }, { "name" : "Augusta National Golf Club" }, { "nickName" : "Augusta" }, { "logoPath" : "augusta.png" } ] ] }
I can see one of 2 things
is that your collection that contains the 2 documents is NOT named playerTest
you are not using the database that contains the playerTest collection
Share the output of:
db.playerTest.find()
db
1 Like
Dan_Burt
(Dan Burt)
May 17, 2021, 12:55pm
3
I feel such a fool… collection wasn’t camelCase! Doh!
Now the correct data is being applied, I also corrected that the previous syntax was created Array
's of Array
's. Updated to. by removing a set of square braces:
db.playertest.updateMany({},{$set: {"clubs": [ { "clubId": ObjectId("6076030465508936f00e086c"), "name": "Augusta National Golf Club", "nickName": "Augusta", "logoPath": "augusta.png"}]}})
1 Like
system
(system)
Closed
May 22, 2021, 12:55pm
4
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.