0.9.2 • Published 3 years ago

@peregrine/mongo-connect v0.9.2

Weekly downloads
19
License
MIT
Repository
github
Last release
3 years ago

Node.js linter & tests Node.js deployment Quality Gate Status license npm node version types

Mongo Connect

Experimental MongoDB lib for node. Wraps the mongoose library.

Notes

  • All objects internally have an _id field for the ID. Don't specify the primary ID in the Schema.
  • When passing or retreiving an object, the _id field will be renamed to id

Demo

import { MongoDB, MutableRepository, required } from "@peregrine/mongo-connect"

type Nullable<T> = T | null

interface Pet {
    name: string
    kind: string
    dateOfBirth?: Date
}

interface PetWithId extends Pet {
    id: string
}

const db = await MongoDB.connect(process.env.MONGO_URL)
const pets: MutableRepository<Pet> = db.getMutableRepository<Pet>("pets", {
    name: required(String),
    kind: required(String),
    dateOfBirth: Date
})

const maya: PetWithId = await pets.add({
    name: "Maya",
    kind: "Parrot"
})

const updatedMaya: Nullable<PetWithId> = await pets.update(maya.id, {
    name: maya.name,
    kind: "Macaw"
})
// OR
const patchedMaya: Nullable<PetWithId> = await pets.patch(maya.id, { kind: "Macaw" })
0.9.2

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.6.0

3 years ago

0.5.0

3 years ago

0.4.0

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.2

3 years ago

0.3.3

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.2.4

4 years ago

0.2.2

4 years ago

0.1.1205

4 years ago

0.2.0

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago