-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
37 changed files
with
10,296 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Build Docs | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'docs/**' | ||
- 'website/**' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build-docs: | ||
name: Build Docs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: yarn | ||
cache-dependency-path: ./website/yarn.lock | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
working-directory: ./website | ||
|
||
- name: Build website | ||
run: yarn build | ||
working-directory: ./website | ||
|
||
# Docs: https://github.com/peaceiris/actions-gh-pages#%EF%B8%8F-docusaurus | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_branch: gh-pages | ||
publish_dir: ./website/build | ||
user_name: lyearnDev | ||
user_email: [email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Test Docs | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- 'docs/**' | ||
- 'website/**' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test-docs: | ||
name: Test Docs | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: yarn | ||
cache-dependency-path: ./website/yarn.lock | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
working-directory: ./website | ||
|
||
- name: Test build website | ||
run: yarn build | ||
working-directory: ./website |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,13 @@ func init() { | |
err := mgod.ConfigureDefaultConnection(cfg, dbName, opts) | ||
} | ||
``` | ||
> [!NOTE] | ||
> The above `err` variable will be a connection error (if occurs) returned by the Go Mongo Driver. So, handle the error accordingly. | ||
|
||
:::note | ||
The above `err` variable will be a connection error (if occurs) returned by the Go Mongo Driver. So, handle the error accordingly. | ||
::: | ||
|
||
Add tags _(wherever applicable)_ in existing struct _(or define a new model)_. | ||
|
||
```go | ||
type User struct { | ||
Name string | ||
|
@@ -46,6 +49,7 @@ type User struct { | |
``` | ||
|
||
Use `mgod` to get the entity ODM. | ||
|
||
```go | ||
import ( | ||
"github.com/Lyearn/mgod" | ||
|
@@ -63,7 +67,8 @@ userModel, _ := mgod.NewEntityMongoModel(model, schemaOpts) | |
|
||
Use the entity ODM to perform CRUD operations with ease. | ||
|
||
Insert a new document. | ||
## Inserting a new document | ||
|
||
```go | ||
joinedOn, _ := dateformatter.New(time.Now()).GetISOString() | ||
userDoc := User{ | ||
|
@@ -75,7 +80,8 @@ user, _ := userModel.InsertOne(context.TODO(), userDoc) | |
``` | ||
|
||
**Output:** | ||
```json | ||
|
||
```js | ||
{ | ||
"_id": ObjectId("65697705d4cbed00e8aba717"), | ||
"name": "Gopher", | ||
|
@@ -86,41 +92,44 @@ user, _ := userModel.InsertOne(context.TODO(), userDoc) | |
"__v": 0 | ||
} | ||
``` | ||
|
||
Notice how `_id`, `createdAt`, `updatedAt` and `__v` fields are added automatically. | ||
|
||
--- | ||
## Finding documents using model properties | ||
|
||
Find documents using model properties. | ||
```go | ||
users, _ := userModel.Find(context.TODO(), bson.M{"name": userDoc.Name}) | ||
``` | ||
|
||
**Output:** | ||
|
||
```go | ||
[]User{ | ||
User{ | ||
Name: "Gopher", | ||
EmailID: "[email protected]", | ||
JoinedOn: "2023-12-01T11:32:19.290Z", | ||
} | ||
} | ||
} | ||
``` | ||
--- | ||
|
||
Update document properties. | ||
## Updating document properties | ||
|
||
```go | ||
result, _ := userModel.UpdateMany(context.TODO(), bson.M{"joinedOn": bson.M{"$gte": "2023-12-01T00:00:00.000Z"}}, bson.M{"$inc": {"__v": 1}}) | ||
``` | ||
|
||
**Output:** | ||
|
||
```go | ||
mongo.UpdateResult{ | ||
MatchedCount: 1, | ||
ModifiedCount: 1, | ||
UpsertedCount: 0, | ||
} | ||
``` | ||
```json | ||
|
||
```js | ||
// User Doc | ||
{ | ||
"_id": ObjectId("65697705d4cbed00e8aba717"), | ||
|
@@ -132,18 +141,19 @@ mongo.UpdateResult{ | |
"__v": 1 | ||
} | ||
``` | ||
|
||
Notice the updation of the `updatedAt` field. | ||
|
||
--- | ||
## Removing documents matching certain or all model properties | ||
|
||
Remove documents matching certain or all model properties. | ||
```go | ||
result, _ := userModel.DeleteMany(context.TODO(), bson.M{"name": userDoc.Name}) | ||
``` | ||
|
||
**Output:** | ||
|
||
```go | ||
mongo.DeleteResult{ | ||
DeletedCount: 1 | ||
} | ||
``` | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.