3

If I have a document in mongodb with this structure:

{
    "_id": "user1",
    "loc": [
        {
            "lon": 51.12076493195686,
            "lat": -113.98040771484375
        },
        {
            "lon": 51.10682735591432,
            "lat": -114.11773681640625
        }
    ]
}

How would I be able to push a new array containing lon and lat within the loc list?

The structure I am trying to use is this: db.collection('location').update({_id:'user1'},{'$push': {"lat": "-107.10400390625", "lon": "33.32343323432" }})

This obviously does not work because the lat and lon are nested within loc.

2
  • I can't try it myself at the moment, but on my opinion only the 'loc' is missing after $push: Commented Mar 9, 2012 at 18:14
  • Yes I added it: db.collection('location').update({_id:'user1'},{"$push": { loc: {lon: 69.09144802136697, lat: -107.10400390625 }}}) This works...thanks. Commented Mar 9, 2012 at 22:00

1 Answer 1

4
db.collection('location').update({_id:'user1'},{'$push': { "loc": {"lat": "-107.10400390625", "lon": "33.32343323432" }}})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.