juicycleff / ultimate-backend

Multi tenant SaaS starter kit with cqrs graphql microservice architecture, apollo federation, event source and authentication
https://juicycleff.github.io/ultimate-backend-docs
MIT License
2.6k stars 407 forks source link

DollarPrefixedFieldName - MongoDB error #171

Open sharife3 opened 3 years ago

sharife3 commented 3 years ago

When running the project and following the steps i came across an issue with findOneAndUpdate in the base-mongo.repository.ts located in the repo-orm lib.

When executing the code it complained with this error:

[Nest] 44633 - [RegisterUserHandler] Object: { "ok": 0, "code": 52, "codeName": "DollarPrefixedFieldName", "name": "MongoError" }

To get this working, i changed the it from { $set: { ...req.updates } } to { ...req.updates }

from:

 async findOneAndUpdate(req: UpdateRequest): Promise<DOC> {
    const collection = await this.collection;
    const updates = await this.invokeEvents(
      PRE_KEY,
      ['UPDATE', 'UPDATE_ONE'],
      { $set: { ...req.updates } },
    );

to:

 async findOneAndUpdate(req: UpdateRequest): Promise<DOC> {
    const collection = await this.collection;
    const updates = await this.invokeEvents(
      PRE_KEY,
      ['UPDATE', 'UPDATE_ONE'],
      { ...req.updates },
    );

Hope this is helpful