Skip to content

Commit ab76af1

Browse files
committed
Adding BSON element post.
1 parent c5081e2 commit ab76af1

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

_drafts/adding-a-new-bson-element.md

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
layout: post
3+
title: "Appending A New BSON Element"
4+
author: Thomas
5+
tags: [ databases, dev, go ]
6+
description: How to add a new element to a BSON.D type in Go
7+
---
8+
9+
When I started building out my latest project, I decided that I wanted to use MongoDB as my database so I could learn another technology. Also [Rick Houlihan](https://twitter.com/houlihan_rick) works with Mongo now, which makes me think that there's something special going on over there. One of the first topics I had to become familiar with while learning MongoDB was BSON. It's similar to JSON but with some extra flavor. Also, I was writing my project in Go, so I was using the [Mongo driver](https://pkg.go.dev/go.mongodb.org/mongo-driver/bson). One thing I quickly stumbled across was needing to add an element to a `bson.D` (also applies to `bson.M`) type (I don't think this type/concept is in other languages like Javascript/Node), and I could not find much online about clean solutions to this. This type of scenario normally encourages me to write up a quick post to share my approach.
10+
11+
```go
12+
filter := bson.D{
13+
{
14+
Key: "mykey",
15+
Value: "someval",
16+
},
17+
}
18+
19+
filter = append(
20+
filter,
21+
bson.E{
22+
Key: "time",
23+
Value: bson.D{{
24+
Key: "$lt",
25+
Value: someTime,
26+
}},
27+
},
28+
)
29+
```
30+
31+
The gist is that you need to `append` the new `bson.E` element to the existing `bson.D`. The reasoning behind this is that the individual elements used in a `bson.D` initialization are converted to `bson.E` types anyway, so we need to create new elements with that same type before adding them in. The value of the appended element can be anything that can normally be passed to `bson.D` including a nested `bson.D` value.

google-calendar-for-helpdesk-privacy-policy.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ title: Google Calendar for HelpDesk Privacy Policy
2222
<p>We may make changes to this Privacy Policy in the future. You should check this page from time to time to ensure you are aware of any changes. Where appropriate we may notify you of such changes.</p>
2323
<h3>2. Information we may collect about you</h3>
2424
<p>We collect and process the following information which may include your personal data.</p>
25-
<p>Your name, last name, email address, phone number, contact data, device’s ID, your user preferences as well as all the data (including personal data) you supply to us and information provided by you when using the Service or website.</p>
25+
<p>Your name, last name, email address, device’s ID, your user preferences as well as all the data (including personal data) you supply to us and information provided by you when using the Service or website.</p>
26+
<p>We collect and process the following Google user data.</p>
27+
<p>Your email address, calendar names, calendar events as well as all the data (including personal data) you supply to us and information provided by you when using the Service or website.</p>
2628
<h3>3. Collecting, processing and using personal data</h3>
2729
<p>We only store and process your personal data when you have voluntarily supplied us with it such as by filling in a contact form or signing up to the Service. Your personal data will only be disclosed or otherwise transmitted if this is necessary to implement the contract, render our Services or you have given your prior consent.</p>
2830
<p>Since we use LiveChat, Inc.’s Services you may be interested in reviewing their privacy policy available under the following links:<br>

0 commit comments

Comments
 (0)