Skip to content

Commit

Permalink
Update Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
khaosdoctor committed Jan 29, 2019
1 parent f3c29b8 commit 0f37b78
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/MongodbEventRepository.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ By default, the class already has some base methods:

> This record should be created when the class is instantiated using the `create` method
- `existBy (query: { [key: string]: any })`: Verify if an object exist (by a query) and returns a boolean flag
- `existBy (query: { [key: string]: any })`: Returns a boolean value to check if an object exists using a given query
- `bulkUpdate (entities: IEventEntity[])`: Save events from several instances of an existing entity at once
- `bulkInsert (entities: IEventEntity[])`: Save events from several instances of an non existing entity at once
- `withSession (session: ClientSession)`: Begins a MongoDB session to initiate a transaction (only on Mongo 4.0) and returns an object with the available methods which can be executed within a session. If this following command throws an error, the whole session suffers a rollback, otherwise it is commited.
Expand Down Expand Up @@ -59,13 +59,15 @@ class PersonRepository extends MongodbEventRepository<Person> {

(async function () {
const personData = { email:'[email protected]', password:'jdoe' }
const connection = (await MongoClient.connect('mongodb://urldomongodbaqui')).db('crowd')
const connection = (await MongoClient.connect('mongodb://mongodburl')).db('crowd')

const personRepository = new PersonRepository(connection)
const existPerson = await personRepository.existBy({ email: emailpersonData.email }) // Returns boolean
if (!existPerson) {
const johnDoe = Person.create(personData.email, personData.password)
await personRepository.save(johnDoe) // Creates a new event
}

const allJanes = await personRepository.search({ name: 'jane' }, 1, 10) // Returns an object following IPaginatedQueryResult interface

johnDoe.changeEmail({ newEmail: '[email protected]' }, 'jdoe')
Expand All @@ -77,4 +79,4 @@ class PersonRepository extends MongodbEventRepository<Person> {
})()
```

> If you version does **not** support transactions, an Database Error is thrown
> If you version does **not** support transactions, an Database Error is thrown

0 comments on commit 0f37b78

Please sign in to comment.