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?
-
2Do any of these methods work in the Mongo shell? I would guess so ... stackoverflow.com/questions/122102/…McGarnagle– McGarnagle2012-06-21 06:56:36 +00:00Commented 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 nowSammaye– Sammaye2012-06-21 07:16:04 +00:00Commented Jun 21, 2012 at 7:16
2 Answers
Ok So if you see here:
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,
5 Comments
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.