mongodb - Using $set to nest value in Meteor using dot notation doesn't work -


i'm having trouble setting nested value in meteor collection. have:

programs.update({ _id: progs[i]._id }, { $set: { "year.roommwk1": room }}); 

my console giving error: "minimongoerror: cannot use part 'roommwk1' traverse c16"

c16 value of current year field. want nest value of roomwk1, '21a', under year field value 'c16'.

not sure i'm going wrong.

edit:

current structure of documents is:

{   "_id" : objectid("56ce676c082e64f956411a3c"),   "recordid" : 8514,   "fullname" : "aidan anderson",   "year" : "c16",   "campyear" : "ssipc16",   "week1" : "1",   "week2" : "2",   "week3" : "0",   "week4" : "0",   "week5" : "0",   "week6" : "",   "notes" : "",   "roomaterequest" : "per, ollie, paul b., linus, sam l.",   "lessonrequest" : "",   "arrivalinfo" : "",   "automobile" : 0,   "repertoire" : "bach" } 

the nesting doesn't exist @ moment, need nest 'roomwk1' 'roomwk5' fields under specific year moving forward.

i put current year selector outside mongo. experience mongo doest [i] var currentyear = progs[i]._id

my guess have multiple years , have following nest. {year: {c16: { roomwk1: room }} }

you can use second selector more control. i'm not sure have in document if there 'year' equivalent add selector. way can use $ in $set

var currentyear = progs[i]._id programs.update({_id: currentyear, 'year': 'c16'}, {$set: {'year.$.roomwk1': room}}}


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -