Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8991455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:43:50+00:00 2026-06-15T22:43:50+00:00

I searched a lot on this topic, but I’m just totally lost. Here is

  • 0

I searched a lot on this topic, but I’m just totally lost.
Here is my problem (I’m using node.js with mongojs):

I’d like to have this kind of documents:

{ 
    "_id" : ObjectId("50ce2f7f98fa09b20d000001"), 
    "beginTime" : 1355689855016, 
    "tags" : {
        "primary": [ 29, 12, 16], 
        "secondary": [6, 8, 9]
    },
    "user" : "50bdddc601de4681d666835f"
}

But if I try to push new tags for example under “primary” (note that this fields come from 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
  }
});

then I get

{ "_id" : ObjectId("50ce2f7f98fa09b20d000001"), "beginTime" : 1355689855016, "tags" : [ { "primary" : 29 }, { "primary" : "24" }, { "primary" : "1" } ], "user" : "50bdddc601de4681d666835f" }

I tried many other variations, including nesting the $push (witch tranformed it into a field o.o). Anyway, I always failed. Also at this point I’m really starving T_T

Please help me. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:43:51+00:00Added an answer on June 15, 2026 at 10:43 pm

    The value of a $push operator needs to be the array field you want pushed to, not the parent.

    Try this instead:

    ...
    return db.activities.update({
      '_id': db.ObjectId(request.body.activity),
      'user': request.session.user.id
    }, {
      $push: {
        'tags.primary': tags.primary,
        'tags.secondary': tags.secondary
      }
    });
    

    UPDATE

    To do this dynamically you need to do something like this:

    ...
    var push = {};
    push['tags.' + request.body.relevance] = request.body.tag;
    return db.activities.update({
      '_id': db.ObjectId(request.body.activity),
      'user': request.session.user.id
    }, {
      $push: push
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Searched a lot about this problem but never found a answer, that solved it.
I searched a lot about this problem but the only results I get is
I've searched a lot of resources for this problem but none of them helped.
I've searched plenty on this topic and have gotten a lot of good (but
Is something like this possible? I searched a lot but the ways I found
I've searched a lot for this on google, but without luck... Basically I need
I am new to this technology. I searched a lot but cant find any
I have searched a lot for this issue. But couldn't find the exact answer.
I searched a lot on this but haven't yet got any standard or rather
I searched a lot to do this but nothing of what I tried work.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.