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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:32:52+00:00 2026-05-31T01:32:52+00:00

I have created an array in my mongo document, so it looks a bit

  • 0

I have created an array in my mongo document, so it looks a bit like the following:

{ "_id" : ObjectId("4f59e19d0b7aab2903000004"), 
  "details" : { x:1, y:2 }
}

I am then trying to push a new value to the array, doing:

db.users.update({"_id" : ObjectId("4f59e19d0b7aab2903000004")},{$push: {"details": {"z":3}}});

However I get the error:

Cannot apply $push/$pushAll modifier to non-array

It seems the only way I am actually able to add the information to the array, is to use dot notation to add it, e.g.

db.users.update({"_id" : ObjectId("4f59e19d0b7aab2903000004")},{"details.z": 3});

That seems to work, but when I have an array of about 30 values, it seems a bit tedious.

Just for clarity, I am using the lithium PHP framework, not just entering these manually, so I could loop through an array to prepend the ‘details.’ to each key, but I don’t think that should be necessary. Is there something I’m missing as to why it won’t push values into the array?

(My lithium code was as follows:)

User::update(array('$push'=>array('details'=>array('z'=>3))), array('_id'=>$id))

Thanks,

Dan

  • 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-31T01:32:54+00:00Added an answer on May 31, 2026 at 1:32 am

    “details” is an embedded document, not an array. If it was an array it would look like this (note the [] indicating an array):

    { "_id" : ObjectId("4f59f0531ae8f3b5f92246fe"), 
           "details" : [ { "x" : 1 }, { "y" : 2 } ] }
    

    If you then do a $push:

    db.users.update({"_id" : ObjectId("4f59f0531ae8f3b5f92246fe")}, 
                    {$push : {"details": {"z":3}}})
    

    You get the expected result:

    db.users.find({"_id" : ObjectId("4f59f0531ae8f3b5f92246fe")})
    
    { "_id" : ObjectId("4f59f0531ae8f3b5f92246fe"), 
      "details" : [ { "x" : 1 }, { "y" : 2 }, { "z" : 3 } ] }
    

    Basically you are trying to push to a document, not an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have created an array of custom objects in my processing code and then
I have created an array of doubles using the following code: double *points =
I have created a multidimensional array in Python like this: self.cells = np.empty((r,c),dtype=np.object) Now
Why does the following code compile and run. I have created an integer array
i have created Array of Linkbutton and when user click on link button it
I have created an array Man: public main blah blah{ man = man[10]; }
I have an array created with this code: var widthRange = new Array(); widthRange[46]
How do I pass an array I have created on the server side onto

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.