How to Do Multi-Object Update in MongoDB From Appery.io Server Code

The Appery.io Database runs on MongoDB database. The following screen shot shows a sample collection (table) with employees in the database.

Screen Shot 2016-04-19 at 5.01.31 PM.png

Custom database collection

You want to update two or more objects in a single request. That’s very simple to do from Appery.io Server Code. The following server script does multi-object update, it just one line of code:

var result = Collection.multiUpdateObject("367e9e77-cc1f-4c1f...",
    "People", '{"title":"Engineer"}', {"title":"Senior Engineer"});
  • The first argument is the database API key.
  • People is the collection name inside the database.
  • With {“title”:”Engineer”} you are searching for all records where the title is set to “Engineer” and update those objects to a title of “Senior Engineer“.
  • Collection is part of Server Code API that integrates with the database.

That’s it.

After you run the script, the database collection looks like this:

Screen Shot 2016-04-20 at 11.35.22 AM

Collection after the update

Appery.io Server Code provides a very nice integration with the Database that allows you to run and execute advanced app logic.

Learn more about Appery.io Database and Server Code from many short videos on our YouTube channel.

2 thoughts on “How to Do Multi-Object Update in MongoDB From Appery.io Server Code

  1. I GOT ERROR:

    Script UpdateY: :1:68 Expected , but found ; var result = Collection.multiUpdateObject(“585f4461e4b02b2c07e11fec”;, ^

    “;” and “,” together at the first sentence is that OK?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s