go-bongo/bongo

Best way to check if exist with some conditions

renatocassino opened this issue · 0 comments

Hello guys

I want to make an endpoint in my application to check if a slug already exists
I made in this way:

connection := storage.DbBongo()
connection.Collection("mycollection").FindOne(bson.M{"slug": slug}, &post)

isAvailable := post.Id == ""
/// RESPONSE IF IS AVAILABLE AFTER

But, in this query to MongoDb I'm getting all post data
I want to make a simple query getting only if exist or not

To simplify, I want to count

Like this:

isAvailable := connection.Collection("communities").Find(bson.M{"slug": slug}).Count() == 0

How can I do this?

Thanks