So I have the following documents:
{
_id:596fc7d71aa95179315b27ea
check:1
pro:1
slug:"ediloc.com marinescu"
}
{
_id:596fd4661aa9517c7709475e
check:0
pro:1
slug:"ediloc.com2"
}
{
_id:5971ea3d1aa9515dcfee30ed
check:0
pro:0
slug:"asirom"
}
{
_id:5971f8871aa9516112e2e997
slug:"aesirom2"
check:0
pro:0
}
{
_id:597b9d741aa951452b8e6028
user_id:596fc73b1aa9517908b8a2f9
slug:"bridgeway"
check:0
pro:0
}
{
_id:597bb6d11aa951452b8e6029
slug:"rca"
check:1
pro:0
}
{
_id:597bce141aa9515587b821ad
slug:"anabella"
check:0
pro:0
}
{
_id:597bceaa1aa9515587b821ae
slug:"diana"
check:0
pro:0
}
{
_id:597bcee31aa9515587b821af
slug:"ananas"
check:0
pro:0
}
{
_id:597bd2a31aa95156f22e24f6
slug:"plaza mall"
check:0
pro:0
}
{
_id:597c63161aa95171192c54fd
slug:"ediloc.com23423fg"
check:1
pro:0
}
And this is my MongoDB query in GO Language, I am retrieving all the documents that contain the string "a" and I sort them by PRO and CHECK fields:
var business []bson.M
oe := bson.M{
"$match": bson.M{"slug": bson.M{"$regex": "a"}},
}
oa := bson.M{
"$project": bson.M {"pro": 1, "check": 1, "slug":1},
}
ol := bson.M{
"$limit" :3,
}
os := bson.M{
"$skip" :skips, //this is 0,3,6,9 etc depending on the page number
}
or := bson.M{
"$sort": bson.D{
bson.DocElem{Name: "pro", Value: -1},
bson.DocElem{Name: "check", Value: -1},
bson.DocElem{Name: "slug", Value: 1},
},
}
pipe := c.Pipe([]bson.M{oe, or, oa, os, ol })
if err := pipe.All(&business); err != nil {
log.Printf(err.Error())
}
Now these are the results that I am getting back for each page.
Page 1:
{
_id:596fc7d71aa95179315b27ea
check:1
pro:1
slug:"ediloc.com marinescu"
}
{
_id:597bb6d11aa951452b8e6029
slug:"rca"
check:1
pro:0
}
{
_id:5971ea3d1aa9515dcfee30ed
check:0
pro:0
slug:"asirom"
}
Page 2:
{
_id:597b9d741aa951452b8e6028
user_id:596fc73b1aa9517908b8a2f9
slug:"bridgeway"
check:0
pro:0
}
{
_id:5971f8871aa9516112e2e997
name:"aesirom2"
check:0
pro:0
}
{
_id:597bce141aa9515587b821ad
slug:"anabella"
check:0
pro:0
}
Page 3:
{
_id:597bce141aa9515587b821ad
slug:"anabella"
check:0
pro:0
}
{
_id:5971f8871aa9516112e2e997
name:"aesirom2"
check:0
pro:0
}
{
_id:597bceaa1aa9515587b821ae
slug:"diana"
check:0
pro:0
}
As you can see there are duplicated results on the second the third page.
Any thoughts how I can write this query so it doesn't retrieve duplicated documents when you go to a different page?