-2

I have only rev id and now I want to retrieve data by rev id in the Couch Db.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Krunal Pandya
  • 204
  • 1
  • 2
  • 12

1 Answers1

2

So you wish to fetch any document that has a specific _rev, regardless of its _id. Leaving aside the obvious "why???" here, there is nothing in the CouchDB API that supports this, as the rev is not intended to be used without a corresponding id.

But if you really want to do this, I guess you could create a view that emits the _rev as the key and then query the view:

function (doc) {
   emit(doc._rev, 1);
}

But note: this is a really bad idea.

xpqz
  • 3,617
  • 10
  • 16
  • OK, but i am not that much good in couch db. Can you please provide me the method to create the view ? – Krunal Pandya Jul 21 '20 at 10:46
  • Can you first explain why you have a rev but not the id? – xpqz Jul 21 '20 at 10:48
  • I think with rev I can retrieve the data but after that I am not do that and now I have some data with only rev. – Krunal Pandya Jul 21 '20 at 10:49
  • I've added the map function to create a view keyed on rev. – xpqz Jul 21 '20 at 10:53
  • 1
    I think you need to read up a bit on how views work, e.g. from https://docs.couchdb.org/en/stable/ddocs/views/intro.html -- but you can enter the map function directly in fauxton (the couchdb dashboard), which is what I did to test out the above. – xpqz Jul 21 '20 at 10:56