1

It's very easy to copy a javascript object in jQuery using jQuery.extend() function call. I am curious is there any way to do the same task in mongodb shell?

2
  • 2
    Do any of these methods work in the Mongo shell? I would guess so ... stackoverflow.com/questions/122102/… Commented Jun 21, 2012 at 6:56
  • No, MongoDB is not JQuery, there is another way. Let me find the link cos I have fogotten how to extend the console now Commented Jun 21, 2012 at 7:16

2 Answers 2

1

Ok So if you see here:

http://www.mongodb.org/display/DOCS/Overview+-+The+MongoDB+Interactive+Shell#Overview-TheMongoDBInteractiveShell-.mongorc.js

You will see:

When the shell is launched, it checks the user's home directory for a javascript file named .mongorc.js.

This .mongorc.js allow you to define custom functions and what not for collection objects and db objects.

To go further here is an example stolen from an unsuspecting gist user: https://gist.github.com/1640154

Hope it helps,

Sign up to request clarification or add additional context in comments.

5 Comments

I don't think this is the exact answer. I think you should explain how can it be done right in the answer.
@cuneytyvz well the OP accepted it. I do realise that extend is not the same as using a mongo.rc however, it seemed to answer the question as such it seems to be the answer. If you have a similar question you should ask it
@cuneytyvz to be fair as well this answer is from 3 years ago, it might be that it turned out that the OP was not clear abut what he was asking and the comments have since been deleted as being too chatty. I just don't remember I am afraid
whether op is accepted or not, it doesn't change the fact that it's not really an answer.
i see, i just wanted to note that :)
0

If I understand your question, you are seeking to add additional attributes to an existing document in your MongoDB collection. This can be done with the update method using the $set updater to add the new attributes, along with their values. The process is described in this MongoDB documentation page for $set.

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.