- step1: connecting to MongoDB
- step2: creating a CLI program
- step3: creating a task
- step4: show all tasks
- step5: complete a task
- step6: displaying pending tasks only
- step7: displaying finished tasks only
- step8: deleting a task
go get go.mongodb.org/mongo-driver
go get github.com/urfave/cli/v2
go get gopkg.in/gookit/color.v1
go get github.com/joho/godotenv
For completing a task we need to grab a string value from command-line in order to identify the task we wanted to update, then with some efforts over creating an appropriate query we do the trick.
Just to be clear you only need to know how to use a good query statement and all the rest is the same code as previous parts.
filter := bson.D {
primitive.E{Key: "completed", Value: true},
}
filter := bson.D{primitive.E{Key: "text", Value: text}}