Lightweight repository abstraction layer on top of the mongodb driver to provide missing features. It has never been so delicious working with mongo
.
✅ _id
mapping to id
. In mongo it's not possible to use id instead of _id, this feature automatically maps id field for you (enabled by default).
✅ _id
transformation from ObjectId
to string
. So you will work with strings always and ObjectId
will be stored in mongo for you. You will not need to worry about conversions any more once it's enabled (enabled by default).
✅ Versioning system can be enabled per collection. version: number
and its increased by 1
every time you call update. Can be used for optimistic concurency.
✅ Doc Dates can be enabled per collection and documents will have createdAt
and updatedAt
.
import { connectMongo, MangoRepo } from 'https://deno.land/x/[email protected]/mod.ts'
type User = {
name: string
avatarUrl: string
}
const { db } = await connectMongo('mongo://localhost/test')
const repo = new MangoRepo<User>(
db,
'users',
)
const result = await repo.insert({
name: 'playerx',
avatarUrl: 'myJokAvatar',
})
console.log(result)
Check out tests/mangoRepo