2

I am very new in couchDB. I have a problem with duplicated entries in my CouchDB database.

In order to solve it I have been reading this: Find The Duplicate value in CouchDb and it is very usuful.

To find duplicates entries I do in Futon:

function(doc) {
    if (doc.ismaster == true && doc.type == "article_aux"){  
        emit([doc.type,doc.id, doc.id_group], doc);
    }
}

On Reduce Function I have

_count

So a duplicated documents has the same id and the same id_group. Here you can see an example about the duplicated entries enter image description here

This is the Json document structure for one document:

{
   "_id": "013684e1d7da89c1b290666a957fd4ce",
   "_rev": "1-c5f41865f78f0806c8df450794edeb1f",
   "type": "article_aux",
   "id": 1661,
   "name": "STEWARTIA SP",
   "security_time": 0,
   "id_reason_type": 0,
   "id_reason": 4,
   "id_group": 3,
   "dose": 2,
   "id_unit_dose": 406,
   "version": "0x000000004821A25D",
   "ismaster": true
}

The field version is an timestamp

The problem I have is I dont know how to remove the duplicated entries.

JoCuTo
  • 2,463
  • 4
  • 28
  • 44
  • First thing you should ask yourself is why is there so much duplicates? Is that intended? If not, fix it. Otherwise, to remove duplicates, you probably want to query all of them. Then, you either want to merge the different versions together to keep the changes or keep the latest one. Then, remove all the other revisions. – Alexis Côté Oct 16 '18 at 15:22
  • 1
    thanks @AlexisCôté is a project develop for other people, I know where is the issue and how to fix it, but first I have to removes all the duplicated document . I wantto keep just one document, the last revision . Remove all the other revions....that is the point ...how? – JoCuTo Oct 16 '18 at 15:33
  • Do you have any document properties that mark the document with a tiomestamp? – Alexis Côté Oct 16 '18 at 16:57
  • @AlexisCôté yes I have something similar , I am going to add my document json structure in my question tomorrow morning – JoCuTo Oct 16 '18 at 21:01

0 Answers0