Start a new topic

Save additional Data after every Safe


following case:

On a "After Save" on a datasource, i wanna manipulate a value in another collection. Thus i'm new to the business collection stuff - can someone give me a statring point to do this? After reading all Documents for the business logic API it's not 100% clear to me...

my code so far:

// To get the entity id of the object in the "other" collection, i want to manipulate. - works finde :)

function onPostSave(request, response, modules){

var eventID = request.body.event_id;

//What's not clear to me is - how i can achieve the saving (update) the value in this other collection. Any starting pont/hint/Code //Example would be great to save us time experimenting :)





function onPostSave(request, response, modules) {

modules.collectionAccess.collection('MyOtherCollection').update({"_id"}, {$set:{"keyName":request.body.keyvalue}});



thanks for your quick answer :)

Sadly your code doesn't seem to work right for me.

(The value just didn't change)

Is there anything else to notice for this?

It's just a normal collection (called "events") containing some data and no error is logged so far.

Best & thanks in advance,


(quick addition) Maybe it's a problem with querying the _id ?

Cause of

collectionAccess.collection('events').find({"public": "personal"}, function (err, userColl) { ....

Works like a charm,

collectionAccess.collection('events').find({"_id": "1234567890abcdef"}, function (err, userColl) {

results in an empty Array for userColl, but the id i'm using is correct.
... Reading through the forum, i found the solution ;)

modules.collectionAccess.collection('events').update({"_id" : modules.collectionAccess.objectID(eventID)}, {$set:{"promised_count":9}}, function(err, docs) {

So i have to use:

modules.collectionAccess.objectID(eventID) instead of just the id "hb24b234b23b4234".

Maybe updating the docs for this? Could be a time-saver for other devs.

Hi Nico,

Glad you found the answer! You're suggestion to update the docs is a good one.
Login or Signup to post a comment