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 7497561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:08:35+00:00 2026-05-29T19:08:35+00:00

im new with mongo and so far have no issue using it. Until i

  • 0

im new with mongo and so far have no issue using it. Until i stuck at this. I need to push a document to an array inside an array. Can refer to json below.

{
    'user_id':'{1231mjnD-32JIjn-3213}',
    'name':'John',
    'campaigns':
        [
            {
                'campaign_id':3221,
                'start_date':'12-01-2012',
                'messages':
                    [
                        {
                            'message_id':211134,
                            'email':'john@gmail.com'
                        }
                    ]
            },
            {
                'campaign_id':3222,
                'start_date':'13-01-2012',
                'messages':
                    [
                        {
                            'message_id':315521,
                            'email':'john@gmail.com'
                        }
                    ]
            }
        ]
}

I want to push one document to an array of messages in a campaigns array(regardless ordering). Meaning that, i need to append new document to an array of messages. And all those messages is from inside another array or campaigns per user. Im using python so my code will be like this.

query = {"user_id" : "{1231mjnD-32JIjn-3213}", "campaigns.campaign_id": 3221}
message = {"message_id":4213122, "email":"john@gmail.com"}
op = {"$push" : {"campaigns.messages":message}}
mongo.TestDatabase.members.update(query, op)

There is no error upon execution. But the document seems to have no changes(no update made). What am i doing wrong here?

  • 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-05-29T19:08:36+00:00Added an answer on May 29, 2026 at 7:08 pm

    Having arrays inside arrays is almost always a bad idea for a number of reasons. I’d put the campaigns in a dedicated collection so they become top level documents.

    That said, you can push to a message array of a specific campaign through :

    db.members.update(
        {"user_id" : "{1231mjnD-32JIjn-3213}", "campaigns.campaign_id": 3221},
        {$push:{"campaigns.$.messages":{"message_id":4213122, "email":"john@gmail.com"}}}
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to javascript/jquery and having a hard time with using this or $(this) to
I'm trying to execute this: <?php // connect $m = new Mongo(); ?> But
Ok i am using mongo db and have a repeating region on my page:
I am new to Mongo DB I have to implement it in java. I
Here's my db: $db = new Mongo(mongodb://u:pw@server.com:37068/dbname); I want to echo a list/array of
I'm running this code: $db = new Mongo(mongodb://user:pw@flame.mongohq.com:27081/dbname); $collection = $db->foobar; $collection->insert($content); I'm trying
I wrote these lines in My Application start event: var mongo = new Mongo();
I need to run/develop a mono-based application on a new dedicated server, and the
I need your advice about framework selection (Java vs Mono) for a new large
I am relatively new to MongoDB, and so far am really impressed. I am

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.