Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDb async/await version 6 Services Differences #28

Open
datajango opened this issue Apr 5, 2019 · 0 comments
Open

MongoDb async/await version 6 Services Differences #28

datajango opened this issue Apr 5, 2019 · 0 comments

Comments

@datajango
Copy link

Version 6 of Nest has a few differences in the way services are handled. The NestJS web sites, the PDF book, and the code here are all out-of-sync with each other? The book on page 129 show book aync/await calls:

from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import { EntrySchema } from './entry.schema';
import { Entry } from './entry.interface';
@Injectable()
export class EntriesService {
constructor(
@InjectModel(EntrySchema) private readonly entryModel:
Model
) {}
// this method retrieves all entries
findAll() {
return this.entryModel.find().exec();
}
// this method retrieves only one entry, by entry ID
findById(id: string) {
return this.entryModel.findById(id).exec();
}
// this method saves an entry in the database
create(entry) {
entry._id = new Types.ObjectId();
const createdEntry = new this.entryModel(entry);
return createdEntry.save();
}
}

the nest web site does:
https://docs.nestjs.com/techniques/mongodb

import { Model } from 'mongoose';
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Cat } from './interfaces/cat.interface';
import { CreateCatDto } from './dto/create-cat.dto';

@Injectable()
export class CatsService {
constructor(@InjectModel('Cat') private readonly catModel: Model) {}

async create(createCatDto: CreateCatDto): Promise {
const createdCat = new this.catModel(createCatDto);
return await createdCat.save();
}

async findAll(): Promise<Cat[]> {
return await this.catModel.find().exec();
}
}

Will this project be upgraded to version 6 with examples of best practices?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant