Mercurial > code > home > repos > gcalendarwatch
view calsync/mongoclient/mongoclient.go @ 56:635ff76f867c
WIP: rewrite: process load+sync in parallel between cals; simplify a lot
author | drewp@bigasterisk.com |
---|---|
date | Thu, 05 Sep 2024 13:50:40 -0700 |
parents | a9b720445bcf |
children | 1f84bd5ce8e0 |
line wrap: on
line source
package mongoclient import ( "context" "log" "time" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" ) type MongoClient struct { ctx context.Context client *mongo.Client db *mongo.Database calsCollection *mongo.Collection eventsCollection *mongo.Collection } // docs in eventsCollection type MongoEvent struct { // e.g. // { // "_id" : "http://bigasterisk.com/calendar/08s5m1_20140929T030000Z", // "htmlLink" : "https://www.google.com/calendar/event?eid=MDhz", // "title" : "meeting", // "feedId" : "drewpca@gmail.com", // "feedTitle" : "drewpca@gmail.com", // "endTimeUnspecified" : false, // "start" : "2014-09-28T20:00:00-07:00", // "startDate" : "2014-09-28", // "startTime" : ISODate("2014-09-29T03:00:00Z"), // "end" : "2014-09-28T21:00:00-07:00", // "endDate" : "2014-09-28", // "endTime" : ISODate("2014-09-29T04:00:00Z") // } Url string `bson:"_id"` GoogleId string `bson:"googleId"` CalendarUrl string `bson:"calendarUrl"` HtmlLink string `bson:"htmlLink"` Title string `bson:"title"` EndTimeUnspecified bool `bson:"endTimeUnspecified"` Start string `bson:"start"` StartDate string `bson:"startDate"` StartTime time.Time `bson:"startTime"` End string `bson:"end"` EndDate string `bson:"endDate"` EndTime time.Time `bson:"endTime"` LastUpdated time.Time `bson:"lastUpdated"` } func New(ctx context.Context) (*MongoClient, error) { log.Println("todo: using fixed ip") mclient, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://10.43.98.221:27017")) if err != nil { return nil, err } db := mclient.Database("pim") return &MongoClient{ ctx, mclient, db, db.Collection("test_gcalendar_cals"), db.Collection("test_gcalendar")}, nil } func (c *MongoClient) Close() { c.client.Disconnect(c.ctx) }