36 lines
654 B
Go
36 lines
654 B
Go
package main
|
||
|
||
import (
|
||
"fmt"
|
||
"log"
|
||
|
||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||
"myschools.me/suguo/mongo-example/mongo"
|
||
)
|
||
|
||
func create() {
|
||
obj, err := mongo.DocumentCreate("person", &Student{
|
||
ID: primitive.NewObjectID(), //ObjectID("000000000000000000000000"),重复插入出现E1100错误
|
||
Name: "王保强",
|
||
Sex: "男",
|
||
})
|
||
if err != nil {
|
||
log.Fatal(err)
|
||
}
|
||
|
||
fmt.Println(obj)
|
||
|
||
obj, err = mongo.DocumentCreate("booking", &Booking{
|
||
ID: primitive.NewObjectID().Hex(),
|
||
Uid: 120,
|
||
IndustryId: 1,
|
||
LocationId: 20,
|
||
BaseLocationId: 853,
|
||
})
|
||
if err != nil {
|
||
log.Fatal(err)
|
||
}
|
||
|
||
fmt.Println(obj)
|
||
}
|