npm

@team_seki/mongodb-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.6.0 • Public • Published

mongodb-plugin

This library was generated with Nx.

Running unit tests

Run nx test mongodb-plugin to execute the unit tests via Jest.

How to use it

import mongoose, {Schema, model} from 'mongoose';
import { Injectable } from '@nestjs/common';
import { MongoDBPlugin } from '@team_seki/mongodb-plugin'

// 1. Create an interface representing a document in MongoDB.
interface IUser {
  name: string;
  email: string;
  avatar?: string;
}

@Injectable()
export class Service {

  // 2. Create a Schema corresponding to the document interface.
  private userSchema = new Schema<IUser>({
    name: { type: String, required: true },
    email: { type: String, required: true },
    avatar: String
  });

  // 3. Create a Model.
  private User = model<IUser>('User', this.userSchema);


  async health(): Promise<{ [key: string]: string }> {

    // 4. create the plugin
    await new MongoDBPlugin({database:"db1"}).client()

    // 5. save the model
    const user = new this.User({
      name: 'Bill',
      email: 'bill@initech.com',
      avatar: 'https://i.imgur.com/dM7Thhn.png'
    });
    await user.save();
    console.log(user.email); // 'bill@initech.com'

    return {
      userId: ${user._id}
    }
  }
}

export default Service;

Readme

Keywords

none

Package Sidebar

Install

npm i @team_seki/mongodb-plugin

Weekly Downloads

47

Version

1.6.0

License

none

Unpacked Size

12.3 kB

Total Files

11

Last publish

Collaborators

  • moisesugarcia
  • kmilo8346
  • dmunozgaete