MongoDB Node / Function

Hello,

It is about the following function that I would like to use with the MongoDB Node:

function getNextSequenceValue(sequenceName){
   var sequenceDocument = db.devices.findAndModify({
      query:{_id: sequenceName },
      update: {$inc:{sequence_value:1}},
      new:true
   });
   return sequenceDocument.sequence_value;
}
db.devices.insert({
   "_id":getNextSequenceValue("productid"),
   "product_name":"Test Device",
   "category":"pc"
})

The function works perfectly with mongosh.
Unfortunately, I can’t manage to implement the function with n8n.
Could someone help me here? I am still a beginner :slight_smile:

Hey @LycaKnight thanks for stepping by :slight_smile:

So I made a simple WF for you, please have a look if this work for you and don’t hesitate to ask if something is not clear for you :slight_smile:

Simon

1 Like