fix cid checks\

This commit is contained in:
SowinskiBraeden committed 2021-10-12 23:07:20 -07:00
1 parent dea4654cb1
commit ff65d9eadc
2 files changed
+6 -4

No files matched your search

+4 -3
View File
@@ -19,13 +19,14 @@ var table = [...]byte{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}
func ValidateID(id string) bool { // true: valid id, false: id already in use
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
err := idCollection.FindOne(ctx, bson.M{"cid": id})
var foundID models.Id
err := idCollection.FindOne(ctx, bson.M{"cid": id}).Decode(&foundID)
cancel()
if err != nil && err.Err() == mongo.ErrNoDocuments {
if err != nil {
var newID models.Id
newID.CID = id
newID.ID = primitive.NewObjectID()
_, insertErr := idCollection.InsertOne(ctx, newID)
_, insertErr := idCollection.InsertOne(context.Background(), newID)
if insertErr != nil {
return false
}