Add new items to a list in mongodb


#1

Consider this:
{"_id": “some unique id”,
" username": “hedisam”,
" followers": [“david”, “sam”]
}

How can I add a new follower to the followers list? PATCH action will remove the existing items from the list. Is it possible without a custom script?


#2

Hey @hedisam, unfortunately I can’t really help you with custom scripting.

DreamFactory supports server-side scripting with Javascript, Node.js, PHP, and Python.

Overview documentation is at http://wiki.dreamfactory.com/DreamFactory/Tutorials#Scripting and http://wiki.dreamfactory.com/DreamFactory/Features/Scripting. There are links in the docs to a few blog posts that should also be helpful.

Thanks!
@AlexBowen


#3

Hey @AlexBowen, Thanks for replying.

Actually I meant “Server Side Scripting”.


#4

You would use a PUT instead of a PATCH.
Which means you would have to get the whole existing record, add your new followers to it, and then PUT the whole new record back into the DB.

MongoDB Patch operator will be supported in the future.