organize + graph
This commit is contained in:
		
							
								
								
									
										22
									
								
								dbs/dbs.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								dbs/dbs.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
package dbs
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"go.mongodb.org/mongo-driver/bson"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Input = map[string]interface{}
 | 
			
		||||
 | 
			
		||||
func InputToBson(i Input, isUpdate bool) bson.D {
 | 
			
		||||
	input := bson.D{}
 | 
			
		||||
	for k, v := range i {
 | 
			
		||||
		if k == "id" {
 | 
			
		||||
			input = append(input, bson.E{Key: "_id", Value: v})
 | 
			
		||||
		} else {
 | 
			
		||||
			input = append(input, bson.E{Key: k, Value: v})
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if isUpdate {
 | 
			
		||||
		return bson.D{{Key: "$set", Value: input}}
 | 
			
		||||
	}
 | 
			
		||||
	return input
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user