Marshall
Marshall

Reputation: 1362

Setting the _id of cloudant in node-red to ensure order of documents

I have a node-red code that works in the following way:

First part It receives a message (json form) and saves it to cloudant DB

Second part Then I can make an http call where I can see all the contents of the DB

This is all good, but the problem is that when it saves it to cloudant, it gives it a random _id, so the order of the documents in the DB isn't the same as the order they came in, but random.

Is there a way to maybe set the _id while saving in node red? Or is there another solution?

I just want that when I call the http it shows it in the order that it came in (last to first, or first to last, doesn't matter).

Upvotes: 1

Views: 567

Answers (1)

hardillb
hardillb

Reputation: 59648

You can set the _id with a function node or a change node before passing it to the Cloudant out node.

But if you just want them in the order they arrived then add the timestamp field and make the query node use a view that sorts the documents by the timestamp

Upvotes: 2

Related Questions