I've been researching extensively on this subject, but I'm completely stumped. Here's my dilemma (I'm working with node.js and mongojs):
I want to create documents like the following:
{
"_id" : ObjectId("50ce2f7f98fa09b20d000001"),
"beginTime" : 1355689855016,
"tags" : {
"primary": [ 29, 12, 16],
"secondary": [6, 8, 9]
},
"user" : "50bdddc601de4681d666835f"
}
However, when I attempt to add new tags under "primary" using variables like so:
tags = {};
tags[request.body.relevance] = request.body.tag;
return db.activities.update({
'_id': db.ObjectId(request.body.activity),
'user': request.session.user.id
}, {
$push: {
tags: tags
}
});
I end up with:
{ "_id" : ObjectId("50ce2f7f98fa09b20d000001"), "beginTime" : 1355689855016, "tags" : [ { "primary" : 29 }, { "primary" : "24" }, { "primary" : "1" } ], "user" : "50bdddc601de4681d666835f" }
I've tried numerous different approaches, even attempted nesting $push (which turned it into a field). Nothing seems to work. At this point, I'm feeling extremely frustrated.
If you have any insights or solutions, please lend me a hand. Much appreciated.