Getting Two and More Document with same Document id

We are using couchbase as server so in some cases we are getting two and more document on same document id (Primary Key) and On client side we are using webstorge(PouchDB ) and for update,insert,delete i’m using couchbase with nodeJS.
but the problem is here why are the multiple document created on same primary key .
PFA for Ref.

It is not possible post the query and output.

@vsr1
Query that is we are running on n1q1 is
select count(uid),uid from bucket_name where type='’ and _deleted is missing group by uid ;
OUTPUT Is:
[
** {
*
** “$1”: 4,**
** “uid”: "_2150e587-23df-4270-9c07-8a92d0d18f96"
** },
*
** {**
** “$1”: 3,**
** “uid”: "_7a8682a6-ad45-4cb6-8812-c0fd4be86049"
** },

** {
*
** “$1”: 3,**
** “uid”: “_73d67238-e0bc-454e-a14c-83cef43d51a6"**
** },**
** {**
** “$1”: 1,**
** “uid”: "_203708c5-320d-4103-8ee6-68ba55b55e3c"
** },

** {
*
** “$1”: 1,**
** “uid”: "
_1496bca4-ee17-42ba-9eda-05ec83be5a99”**
** }]**

When I’m running the Meta Query from select the one uid from output;-

select Meta(profile_detail).id from profile_detail where type=‘doctor’ and _deleted is missing and uid='*_7a8682a6-ad45-4cb6-8812-c0fd4be86049’;
the out of this query is

[
{
“id”: “_sync:rb:R8A1Z5epewswSJFTsBv0+yieW2iF5xBomulSf8h5xrM=”
},
{
“id”: “_sync:rb:lJo5+2bgfek5otHWGqnd1AoHBRQA5OkddqgbZIO4mUU=”
},
{
“id”: “*****_54ea9784-7428-44ec-b37e-ae9ceb07ba30”
}
]

Becoz of the main document that was I’m create using NodeJS then it’s trace by sync gateway so sync is auto create the document as you can see the doc id’s

"id": "_sync:rb:R8A1Z5epewswSJFTsBv0+yieW2iF5xBomulSf8h5xrM="

},
{
“id”: “_sync:rb:lJo5+2bgfek5otHWGqnd1AoHBRQA5OkddqgbZIO4mUU=”
},

the query is
select Meta(profile_detail).id from profile_detail where type=‘doctor’ and _deleted is missing and uid=‘doctor_54ea9784-7428-44ec-b37e-ae9ceb07ba30’;
and the output we got is

[
{
“id”: “_sync:rb:R8A1Z5epewswSJFTsBv0+yieW2iF5xBomulSf8h5xrM=”
},
{
“id”: “_sync:rb:lJo5+2bgfek5otHWGqnd1AoHBRQA5OkddqgbZIO4mUU=”
},
{
“id”: “doctor_54ea9784-7428-44ec-b37e-ae9ceb07ba30”
}
]

and another query that we are running is

select count(uid),uid from profile_detail where type=‘doctor’ and _deleted is missing group by uid;

OUTPUT we can find in

Attachment

@ervijjusty It seems to me that there is a confusion here between meta().id (which is the actual document key) and uid, which is a field in your documents.

meta().id is a primary key of document.

Correct. It would be unique for each document. However uid is just a user field in the document, so there is no guarantees that it will be unique.
With these clarifications, do you still have issues?

@davids

select Meta(profile_detail).id from profile_detail where type=‘doctor’ and _deleted is missing and uid=‘doctor_54ea9784-7428-44ec-b37e-ae9ceb07ba30’;
and the output we got is

[
{
“id”: “_sync:rb:R8A1Z5epewswSJFTsBv0+yieW2iF5xBomulSf8h5xrM=”
},
{
“id”: “_sync:rb:lJo5+2bgfek5otHWGqnd1AoHBRQA5OkddqgbZIO4mUU=”
},
{
“id”: “doctor_54ea9784-7428-44ec-b37e-ae9ceb07ba30”
}
]

Actually we created a document with id (doctor_54ea9784-7428-44ec-b37e-ae9ceb07ba30) and we are using sync gateway on same bucket. But Two documents had automatically created by sync gateway (_sync:rb:R8A1Z5epewswSJFTsBv0+yieW2iF5xBomulSf8h5xrM= and _sync:rb:lJo5+2bgfek5otHWGqnd1AoHBRQA5OkddqgbZIO4mUU=). which is creating ambiguity in our database. We are accessing same document on various devices.

can you please help us how can we handle this sync document properly.

Regards,
Vijay

I see. Please review What are "_sync:rb" documents? and see if it answers your question.

@davids , How can we delete this document and how is there any way where we can get to know this is sync:rb document. Means do you have any status for the sync:rb documents

Thanks
Vijay

SELECT META().id 
FROM  profile_detail
WHERE  META().id LIKE "\_sync:rb:%";

SELECT META().id 
FROM  profile_detail
WHERE  META().id NOT LIKE "\_sync:rb:%";

select Meta(profile_detail).id
 from profile_detail 
where type=‘doctor’ and _deleted is missing and uid=‘doctor_54ea9784-7428-44ec-b37e-ae9ceb07ba30’ AND META(profile_detail).id NOT LIKE "_sync:rb:%" ;

Sync Gateway stores a number of internal documents in the bucket with the _sync prefix. These documents shouldn’t be modified, as they are required for replication. Any application processing against a mobile-enabled bucket needs to account for these documents. Typically this is just a matter of filtering these from N1QL queries, as outlined in the previous response.