1

I'm attempting to update many field titles in my meteor database (mongodb) and I'm struggling with syntax. Here is an example of one entry in my collection called 'Lessons':

{
"_id": "R6AnePqKecNNe7dkr",
"title": "A Title Name",
"categoryA": "Category Name"
}

I'm trying to update every file within the 'Lessons' collection to replace 'categoryA' with 'category0' and this is the code I'm running based on the answer here:

Lessons.update({}, {$rename:{"categoryA":"category0"}}, { upsert:false, multi:true });

I tried running it within the client shell but it came up with an error "Not permitted. Untrusted code may only update documents by ID." which I attribute to this.

Then I tried running it within the server shell but it said 'Lessons.update' is not recognized as an internal or external command"

Then I made a button within my site and when clicked it would run that code in a method on the server side. There are no errors or warnings when the button is pressed but the database remains unchanged.

I've also tried using 'updateMany' instead of 'update' but that just just comes up with an 'internal server error [500]'

Community
  • 1
  • 1
Josh McGee
  • 443
  • 6
  • 16

1 Answers1

0

the solution is to run the mongo shell on the server

meteor mongo

then select the meteor database

use meteor

then use the following syntax

db.lessons.update({},{$rename:{"categoryA":"category0"}}, {multi:true})
Josh McGee
  • 443
  • 6
  • 16