1

I am working on some conflict resolution, and I am running through a test database that has a worrisome number of conflicts. I am looking for a way to watch a burn down of the conflicts to verify that my script is working. Is there a way to retrieve a listing of all the document IDs that have conflicts?

I tried things like https://server/db/_all_docs?include_docs=true&conflicts=true but this returns everything, conflicted or not. I just want the IDs of documents that have conflicts, ideally I don't need the conflict revs themselves, just the doc id.

Is this possible?

My other thought, a much more manual process, is to write a script to get all the docs, then loop through all of them, using the get command to get with conflicts, then log them all.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Trevor
  • 2,792
  • 1
  • 30
  • 43

2 Answers2

1

The method prescribed by CouchDB: The Definitive Guide, is to create a view function such as this:

function(doc) {
  if(doc._conflicts) {
    emit(doc._conflicts, null);
  }
}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
0

This is what I ended up doing, works decently well. Would be nice to do this without a script.

<?php
ini_set('memory_limit', '-1');

$username = 'test';
$password = 'test';
$couchServer = 'server';
$dbName = 'db';

$couchDb = new CouchDB($username, $password, $couchServer, 5100);

//getAllDocuments returns the results of this command
//https://server/db/_all_docs?include_docs=true&conflicts=true
$results = $couchDb->getAllDocuments($dbName);

//get all the documents with conflicts
$filteredResults = array_filter($results->rows, function ($value) {
    return isset($value->doc->_conflicts) && count($value->doc->_conflicts) > 0;
});

//convert the class to assoc array
$encodedResults=json_decode(json_encode($filteredResults),true);

//use array column to get all the Ids
$docIds=array_column($encodedResults, "id");
var_dump($docIds);
Trevor
  • 2,792
  • 1
  • 30
  • 43