loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.93k stars 1.06k forks source link

MongoDB connector silently failing to insert document in AWS Cluster #6173

Closed diegomarquezp closed 3 years ago

diegomarquezp commented 4 years ago

Hi there. I'm switching my local test database to one in the AWS cloud. I created a cluster with Atlas and I can connect to it using DBCompass. I changed the datasource settings for my app to point into this new cluster and it runs correctly.

The problem is that when I insert a document using this.repo.create() it even returns the created object with its own ObjectID and stuff, but when I do the double-check using DBCompass, no document seems to be inserted at all (I had two windows pointing both to my local db and the AWS cluster to ensure I was not missing the right database). I switched back to my local datasource to confirm the problem and it seems to be correctly inserting documents when I check with DBCompass, so the problem seems to occur only with this AWS cluster

I was wondering if there was any thrown/caught exception by using VSCode debugger, but nope, no exception at all is occurring when pointing to the AWS cluster.

I'm hoping that this is a common situation when dealing with mongo atlas.

Here is some info:

lb4 --version
@loopback/cli version: 2.12.0

@loopback/* dependencies:
  - @loopback/authentication: ^5.0.0
  - @loopback/boot: ^2.4.1
  - @loopback/build: ^6.2.0
  - @loopback/context: ^3.9.4
  - @loopback/core: ^2.9.3
  - @loopback/metadata: ^2.2.4
  - @loopback/openapi-spec-builder: ^2.1.11
  - @loopback/openapi-v3: ^3.4.7
  - @loopback/repository-json-schema: ^2.4.8
  - @loopback/repository: ^2.11.0
  - @loopback/rest: ^6.0.0
  - @loopback/testlab: ^3.2.2
  - @loopback/docs: ^3.13.0
  - @loopback/example-hello-world: ^2.1.7
  - @loopback/example-log-extension: ^2.1.7
  - @loopback/example-rpc-server: ^2.1.7
  - @loopback/example-todo: ^3.7.0
  - @loopback/example-soap-calculator: ^2.4.0
  - @loopback/service-proxy: ^2.3.6
  - @loopback/http-caching-proxy: ^2.1.11
  - @loopback/http-server: ^2.1.11
  - @loopback/example-todo-list: ^3.5.0
  - @loopback/dist-util: ^0.4.0
  - @loopback/rest-explorer: ^2.2.8
  - @loopback/eslint-config: ^9.0.0
  - @loopback/example-express-composition: ^2.4.0
  - @loopback/example-greeter-extension: ^2.1.7
  - @loopback/booter-lb3app: ^2.2.7
  - @loopback/example-lb3-application: ^2.4.0
  - @loopback/example-greeting-app: ^2.2.5
  - @loopback/example-context: ^2.1.7
  - @loopback/repository-tests: ^0.12.11
  - @loopback/extension-health: ^0.4.11
  - @loopback/authorization: ^0.6.4
  - @loopback/rest-crud: ^0.8.11
  - @loopback/security: ^0.2.16
  - @loopback/authentication-passport: ^2.1.11
  - @loopback/example-metrics-prometheus: ^0.3.7
  - @loopback/extension-metrics: ^0.3.11
  - @loopback/model-api-builder: ^2.1.11
  - @loopback/extension-logging: ^0.3.11
  - @loopback/example-access-control-migration: ^2.2.0
  - @loopback/example-file-transfer: ^1.5.0
  - @loopback/example-rest-crud: ^1.6.0
  - @loopback/apiconnect: ^0.4.1
  - @loopback/example-validation-app: ^1.7.0
  - @loopback/cron: ^0.2.11
  - @loopback/example-multi-tenancy: ^0.6.0
  - @loopback/example-passport-login: ^1.5.3
  - @loopback/authentication-jwt: ^0.5.0
  - @loopback/context-explorer: ^0.1.11
  - @loopback/express: ^1.3.0
  - @loopback/example-todo-jwt: ^1.3.0
  - @loopback/mock-oauth2-provider: ^0.1.5
  - @loopback/pooling: ^0.2.0
  - @loopback/typeorm: ^0.1.1

The silently failing code Returns inserted object with object id, but actual document is not inserted in cluster

    async signUp(
        @requestBody({
            content: {
                'application/json': {
                    schema: getModelSchemaRef(NewUserRequest, {
                        title: 'NewUser',
                    }),
                },
            },
        })
        newUserRequest: NewUserRequest,
    ): Promise<User> {
        const password = await hash(newUserRequest.password, await genSalt());
        const savedUser = await this.userRepository.create(
            _.omit(newUserRequest, 'password'),
        );

        await this.userRepository.userCredentials(savedUser.id).create({ 
            password,
            roles: ['customer']
        });

        return savedUser;
    }

My datasource (lb4 does not complain, seems to accept this config):

const config = {
  name: 'main',
  connector: 'mongodb',
  url: 'mongodb+srv://****:****@****.ggfzy.mongodb.net/test',
  host: '****-shard-00-01.ggfzy.mongodb.net:27017,****-shard-00-00.ggfzy.mongodb.net:27017,****-shard-00-02.ggfzy.mongodb.net:27017',
  port: 27017,
  user: '****i',
  password: '****',
  database: '****',
  useNewUrlParser: true
};

Thanks in advance for any help

stale[bot] commented 3 years ago

This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.

stale[bot] commented 3 years ago

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.