我的NestJS后端需要连接到mongodb云,我从跟踪文档
终端中出现以下错误:
(node:6920) UnhandledPromiseRejectionWarning: MongoParseError: URI malformed
at new ConnectionString (D:\growth\quizbackend\quizbackend\node_modules\mongodb-connection-string-url\src\index.ts:113:13)
at Object.parseOptions (D:\growth\quizbackend\
我正在创建应用程序,在其中我有趣地使用NestJs框架,并使用mongodb数据库和mongoose,我尝试保存在数据库中的嵌套数据结构,但是当我保存它时它会抛出错误。以下是我的错误:
[Nest] 11196 - 19/02/2022, 6:01:30 pm ERROR [ExceptionsHandler] Cannot set property 'city' of undefined
TypeError: Cannot set property 'city' of undefined
at UserService.addUser (D:\nest\n
我使用以下npm命令安装了@nestjs/mongoose:
npm i --save @nestjs/mongoose mongoose
但是,当我试图使用这个应用程序时,我会发现以下错误:
node_modules/@nestjs/mongoose/dist/decorators/prop.decorator.d.ts:2:44 - error TS2694: Namespace '"mongoose"' has no exported member 'SchemaTypeOpts'.
export declare type PropOpt
我看过来自的Mongo测试的例子。
该示例测试并具有来自服务的方法的模拟实现,但我还没有达到这个目的。我已经提供了getModelToken,但在我的情况下,这似乎不起作用。
这是我收到的错误消息,下面是我的代码片段:
ShibeService › should be defined
Nest can't resolve dependencies of the ShibeModel (?). Please make sure that the argument DatabaseConnection at index [0] is available in the Mongoo
我正在说明如何学习Nestjs,并启动了一个基本的“任务应用程序”,但我开始在项目中使用猫鼬,并显示了一个错误:
> Potential solutions:
- If TaskModel is a provider, is it part of the current AppModule?
- If TaskModel is exported from a separate @Module, is that module imported within AppModule?
@Module({
imports: [ /* the Module containing Task
我想在NestJS服务中注入mongo模型。该模型仅存在于根模块中。
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { IFolderModel } from './interfaces/folder.interface';
@Injectable()
export class FolderService {
我需要根据一个环境变量在Mongoose中更改一个属性的默认值,但是当我尝试访问process.env.NAME时,我会得到未定义的值,而不是我的.env文件中的值。我在我的模式中有这个
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
export type PetDocument = Pet & Document;
@Schema()
export class Pet {
@Prop({ de
我正在尝试在Nestjs项目中使用mongoose pagent-v2。我的模式如下:
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
export type CarDocument = Car & Document;
import * as mongoosePaginate from 'mongoose-paginate-v2';
@Schema()
export class C
我在nest项目中使用了猫鼬包,但是当我试图使用npm run build.Then构建该项目时,它在控制台中抛出的错误如下:
node_modules/mongoose/node_modules/mongodb/mongodb.d.ts:34:15 - error TS2305: Module '"tls"'
has no exported member 'TLSSocketOptions'.
34 import type { TLSSocketOptions } from 'tls';
我甚至将mongoose包更新为最新
在我的nestjs项目中,我在尝试使用TypeError: callback is not a function ()时使用猫鼬并获取model.save。
"@nestjs/common": "^8.0.0",
"@nestjs/config": "^1.2.0",
"@nestjs/core": "^8.0.0",
"@nestjs/mongoose": "^9.0.2",
"mongoose": "^6.2.6",
在用于存储数据
我试图在NestJs(typeScript)项目中使用mangoose和@nestjs/mongoose库创建自我破坏模式,但无法纠正实现该模式的方法。我知道如何在express框架中使用js来完成这一任务,但没有找到任何用于TS和NestJ的文档。
还像下面这样更新了我的代码,但仍然无法工作
import { Prop, Schema, SchemaFactory, SchemaOptions } from '@nestjs/mongoose';
import * as mangoose from 'mongoose';
export type OtpDoc