Increment String

hi I need Increment String by one but I cant
sow I convert to number for incremented but nothing

and this

var id = Number(msg.payload[0]._id);
id++;
msg.payload[0].ack_id = (id).toString();
node.send(msg);

not work
any help

This is because your id string contains letters and not just numbers. So the Number() method returns NaN not a number.
Johannes
Edit here is a link that explains this behavior of the Number() Method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number

1 Like

If you are using it just to confirm receipt, why not simply return the _id (i.e. why do you have to increment it?)

1 Like

oh yes am wrong I thought HEX valeu

this NEXT Record from MongoDB
so I need find this id into database for check its present or not

Ok,so is that an automatic ID or does your systems generate it?

If it's automatically generated by mongo I'm not certain you can guarantee the next id will be hex+1

this Auto ID generated by mongodb when store any thing

Then I'm struggling to understand the logic. Anyhow, assuming it's always alphanumerically greater then can't you select next record(s) where _id I'd greater than _id?

E.g...

db.products.find({_id: {$gt: ObjectId("4fdbaf608b446b0477000142" )}}).sort({_id:1}).limit(1);
2 Likes

ok I am solved with add UUID node generator to any new incoming event and not ACK type of msg
before stored in dB

yes its logic to work

but I see this error

Actually, not sure how you'd do this ina function node.

Normally in a nodejs project ObjectId is imported

E.g. var ObjectId = require('mongodb').ObjectID;

Does the mongo nodes have a find node? Or a means of accessing ObjectId?

Sorry, I don't know how to help here.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.