# Increment String

**URL:** https://discourse.nodered.org/t/increment-string/25495
**Category:** General
**Created:** [25 April 2020 18:10 UTC](https://discourse.nodered.org/t/increment-string/25495 "2020-04-25T18:10:31Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)
#### Post date: [25 April 2020 18:10 UTC](https://discourse.nodered.org/t/increment-string/25495/1 "2020-04-25T18:10:31Z")

</div>

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

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/3/33cbe02916e2c4bba4d0ecac72b2e6af49e4465a.png)

and this

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

```

not work  
any help

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [25 April 2020 18:17 UTC](https://discourse.nodered.org/t/increment-string/25495/2 "2020-04-25T18:17:20Z")

</div>

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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [25 April 2020 18:22 UTC](https://discourse.nodered.org/t/increment-string/25495/3 "2020-04-25T18:22:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)
#### Post date: [25 April 2020 18:24 UTC](https://discourse.nodered.org/t/increment-string/25495/4 "2020-04-25T18:24:16Z")

</div>

oh yes am wrong I thought HEX valeu

---

<div class="post-metadata">

### Author: ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)
#### Post date: [25 April 2020 18:28 UTC](https://discourse.nodered.org/t/increment-string/25495/5 "2020-04-25T18:28:34Z")

</div>

> [@Steve-Mcl](#):
>
> If you are using it just to confirm receipt, why not simply return the \_id (i.e. why do you have to increment it?)

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

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d14b5d6f898c9d5421a8dd4e3c46ce508f59428.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [25 April 2020 18:31 UTC](https://discourse.nodered.org/t/increment-string/25495/6 "2020-04-25T18:31:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)
#### Post date: [25 April 2020 18:45 UTC](https://discourse.nodered.org/t/increment-string/25495/7 "2020-04-25T18:45:59Z")

</div>

this Auto ID generated by mongodb when store any thing

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [25 April 2020 19:04 UTC](https://discourse.nodered.org/t/increment-string/25495/8 "2020-04-25T19:04:33Z")

</div>

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...

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

```

---

<div class="post-metadata">

### Author: ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)
#### Post date: [25 April 2020 20:18 UTC](https://discourse.nodered.org/t/increment-string/25495/9 "2020-04-25T20:18:02Z")

</div>

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

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d46eb16771ef3bd7b0f958a1c6d08336e6d3193c.png)

---

<div class="post-metadata">

### Author: ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)
#### Post date: [25 April 2020 20:33 UTC](https://discourse.nodered.org/t/increment-string/25495/10 "2020-04-25T20:33:46Z")

</div>

> [@Steve-Mcl](#):
>
> 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...

yes its logic to work

---

<div class="post-metadata">

### Author: ![d0d04m3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/d0d04m3/32/19965_2.png) [@d0d04m3](https://discourse.nodered.org/u/d0d04m3)
#### Post date: [25 April 2020 20:43 UTC](https://discourse.nodered.org/t/increment-string/25495/11 "2020-04-25T20:43:59Z")

</div>

but I see this error

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a51162532d6700caa5bf3820f6dbc3caaeb675e.png)

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [25 April 2020 23:31 UTC](https://discourse.nodered.org/t/increment-string/25495/12 "2020-04-25T23:31:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [9 May 2020 23:31 UTC](https://discourse.nodered.org/t/increment-string/25495/13 "2020-05-09T23:31:26Z")

</div>

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