mongo | The MongoDB Database | Database library

 by   mongodb C++ Version: r6.3.0-rc1 License: Non-SPDX

kandi X-RAY | mongo Summary

mongo is a C++ library typically used in Database, MongoDB applications. mongo has no bugs, it has no vulnerabilities and it has medium support. However mongo has a Non-SPDX License. You can download it from GitHub.
You can install compass using the install_compass script packaged with MongoDB:. This will download the appropriate MongoDB Compass package for your platform and install it.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        mongo has a medium active ecosystem.
                        summary
                        It has 23419 star(s) with 5475 fork(s). There are 1225 watchers for this library.
                        summary
                        It had no major release in the last 6 months.
                        summary
                        mongo has no issues reported. There are 68 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of mongo is r6.3.0-rc1
                        mongo Support
                          Best in #Database
                            Average in #Database
                            mongo Support
                              Best in #Database
                                Average in #Database

                                  kandi-Quality Quality

                                    summary
                                    mongo has no bugs reported.
                                    mongo Quality
                                      Best in #Database
                                        Average in #Database
                                        mongo Quality
                                          Best in #Database
                                            Average in #Database

                                              kandi-Security Security

                                                summary
                                                mongo has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                mongo Security
                                                  Best in #Database
                                                    Average in #Database
                                                    mongo Security
                                                      Best in #Database
                                                        Average in #Database

                                                          kandi-License License

                                                            summary
                                                            mongo has a Non-SPDX License.
                                                            summary
                                                            Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
                                                            mongo License
                                                              Best in #Database
                                                                Average in #Database
                                                                mongo License
                                                                  Best in #Database
                                                                    Average in #Database

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        mongo releases are not available. You will need to build from source code and install.
                                                                        summary
                                                                        Installation instructions are not available. Examples and code snippets are available.
                                                                        mongo Reuse
                                                                          Best in #Database
                                                                            Average in #Database
                                                                            mongo Reuse
                                                                              Best in #Database
                                                                                Average in #Database
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
                                                                                  Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  mongo Key Features

                                                                                  The MongoDB Database

                                                                                  mongo Examples and Code Snippets

                                                                                  Generate mongo doc .
                                                                                  javadot imgLines of Code : 17dot imgLicense : Permissive (MIT License)
                                                                                  copy iconCopy
                                                                                  
                                                                                                                      private  List generateMongoDocs(List lines, Class type) { ObjectMapper mapper = new ObjectMapper(); List docs = new ArrayList<>(); for (String json : lines) { try { if (type != null) { T v = mapper.readValue(json, type); json = mapper.writeValueAsString(v); } docs.add(Document.parse(json)); } catch (Throwable e) { log.error("parsing: " + json, e); } } return docs; }
                                                                                  Create mongo template .
                                                                                  javadot imgLines of Code : 15dot imgLicense : Permissive (MIT License)
                                                                                  copy iconCopy
                                                                                  
                                                                                                                      @Bean public MongoTemplate mongoTemplate() throws Exception { int randomPort = SocketUtils.findAvailableTcpPort(); ImmutableMongodConfig mongoDbConfig = MongodConfig.builder() .version(Version.Main.PRODUCTION) .net(new Net(HOST, randomPort, Network.localhostIsIPv6())) .build(); MongodStarter starter = MongodStarter.getDefaultInstance(); MongodExecutable mongodExecutable = starter.prepare(mongoDbConfig); mongodExecutable.start(); return new MongoTemplate(MongoClients.create(String.format(CONNECTION_STRING, HOST, randomPort)), "mongo_auth"); }
                                                                                  Create mongo client .
                                                                                  javadot imgLines of Code : 6dot imgLicense : Permissive (MIT License)
                                                                                  copy iconCopy
                                                                                  
                                                                                                                      @Bean public MongoClient mongo() throws Exception { final ConnectionString connectionString = new ConnectionString("mongodb://localhost:27017/test"); final MongoClientSettings mongoClientSettings = MongoClientSettings.builder().applyConnectionString(connectionString).build(); return MongoClients.create(mongoClientSettings); }
                                                                                  Community Discussions

                                                                                  Trending Discussions on mongo

                                                                                  How to obtain MongoDB version using Golang library?
                                                                                  chevron right
                                                                                  Getting no overload matches this call running mongoose with typescript and express
                                                                                  chevron right
                                                                                  Why can't I use azure file share in my docker-compose to store mongodb data in Azure Container Instance?
                                                                                  chevron right
                                                                                  react-query: useQuery returns undefined and component does not rerender
                                                                                  chevron right
                                                                                  pymongo [SSL: CERTIFICATE_VERIFY_FAILED]: certificate has expired on Mongo Atlas
                                                                                  chevron right
                                                                                  angular 13: Module not found: Error: Can't resolve 'rxjs/operators'
                                                                                  chevron right
                                                                                  Error: grid.mongo.GridStore is not a consstructor ,Using mongoose, Grid-fs-stream and grid multer storage
                                                                                  chevron right
                                                                                  @EnableAutoConfiguration(exclude =...) on tests failed in Spring Boot 2.6.0
                                                                                  chevron right
                                                                                  How do I connect to MongoDB, running in Github codespaces, using MongoDB Compass?
                                                                                  chevron right
                                                                                  mongodb unable establish remote cursors
                                                                                  chevron right

                                                                                  QUESTION

                                                                                  How to obtain MongoDB version using Golang library?
                                                                                  Asked 2022-Mar-28 at 05:54

                                                                                  I am using Go's MongodDB driver (https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.8.0/mongo#section-documentation) and want to obtain the version of the mongoDB server deployed.

                                                                                  For instance, if it would been a MySQL database, I can do something like below:

                                                                                  db, err := sql.Open("mysql", DbUser+":"+DbPwd+"@tcp("+Host+")/"+DbName)
                                                                                  if err != nil {
                                                                                      log.Printf("Error while connecting to DB: %v", err)
                                                                                  }
                                                                                  defer db.Close()
                                                                                  
                                                                                  var dbVersion string
                                                                                  if err := db.QueryRow("SELECT VERSION()").Scan(&dbVersion); err != nil {
                                                                                      dbVersion = "NA"
                                                                                      log.Printf("Couldnt obtain db version: %w", err)
                                                                                  }
                                                                                  fmt.Println("DB Version: ", dbVersion)
                                                                                  

                                                                                  I went through the documentation but am not able to find a clue.

                                                                                  I also need to fetch other metadata like Size of a particular database etc.

                                                                                  Any help would be appreciated. Thanks!

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-26 at 08:04

                                                                                  The MongoDB version can be acquired by running a command, specifically the buildInfo command.

                                                                                  Using the shell, this is how you could do it:

                                                                                  db.runCommand({buildInfo: 1})
                                                                                  

                                                                                  The result is a document whose version property holds the server version, e.g.:

                                                                                  {
                                                                                      "version" : "5.0.6",
                                                                                      ...
                                                                                  }
                                                                                  

                                                                                  To run commands using the official driver, use the Database.RunCommand() method.

                                                                                  For example:

                                                                                  // Connect to MongoDB and acquire a Database:
                                                                                  
                                                                                  ctx := context.Background()
                                                                                  opts := options.Client().ApplyURI("mongodb://localhost")
                                                                                  client, err := mongo.Connect(ctx, opts)
                                                                                  if err != nil {
                                                                                      log.Fatalf("Failed to connect to db: %v", err)
                                                                                  }
                                                                                  defer client.Disconnect(ctx)
                                                                                  
                                                                                  db := client.Database("your-db-name")
                                                                                  
                                                                                  // And now run the buildInfo command:
                                                                                  
                                                                                  buildInfoCmd := bson.D{bson.E{Key: "buildInfo", Value: 1}}
                                                                                  var buildInfoDoc bson.M
                                                                                  if err := db.RunCommand(ctx, buildInfoCmd).Decode(&buildInfoDoc); err != nil {
                                                                                      log.Printf("Failed to run buildInfo command: %v", err)
                                                                                      return
                                                                                  }
                                                                                  log.Println("Database version:", buildInfoDoc["version"])
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71616694

                                                                                  QUESTION

                                                                                  Getting no overload matches this call running mongoose with typescript and express
                                                                                  Asked 2022-Feb-23 at 04:01

                                                                                  I am getting the below error for useNewUrlParser, useUnifiedTopology, useCreateIndex:

                                                                                  No overload matches this call.
                                                                                    Overload 1 of 3, '(uri: string, callback: CallbackWithoutResult): void', gave the following error.
                                                                                      Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; useCreateIndex: boolean; }' is not assignable to parameter of type 'CallbackWithoutResult'.
                                                                                        Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type 'CallbackWithoutResult'.
                                                                                    Overload 2 of 3, '(uri: string, options?: ConnectOptions | undefined): Promise', gave the following error.
                                                                                      Argument of type '{ useNewUrlParser: boolean; useUnifiedTopology: boolean; useCreateIndex: boolean; }' is not assignable to parameter of type 'ConnectOptions'.
                                                                                        Object literal may only specify known properties, and 'useNewUrlParser' does not exist in type 'ConnectOptions'.
                                                                                  

                                                                                  Index.ts

                                                                                  import express from 'express'
                                                                                  import { errorHandler } from './middleware/error-handler';
                                                                                  import router from './router'
                                                                                  import mongoose from 'mongoose'
                                                                                  
                                                                                  const app = express()
                                                                                  
                                                                                  app.use(express.json())
                                                                                  app.use('/api/users', router)
                                                                                  app.use(errorHandler)
                                                                                  
                                                                                  const start = async () => {
                                                                                    try {
                                                                                      await mongoose.connect("mongodb://auth-mongo-srv:27017/auth", {
                                                                                        useNewUrlParser: true,    // error here
                                                                                        useUnifiedTopology: true,
                                                                                        useCreateIndex: true,
                                                                                      });
                                                                                      console.log("Connected to MongoDb");
                                                                                    } catch (err) {
                                                                                      console.error(err);
                                                                                    }
                                                                                  };
                                                                                  
                                                                                  const PORT = 3000
                                                                                  app.listen(PORT, () => {
                                                                                      console.log("working on port ",PORT)
                                                                                  })
                                                                                  
                                                                                  start()
                                                                                  

                                                                                  tsconfig.json

                                                                                  {
                                                                                    "compilerOptions": {
                                                                                  "target": "es6",
                                                                                  "module": "commonjs", 
                                                                                  "esModuleInterop": true, 
                                                                                  "forceConsistentCasingInFileNames": true,
                                                                                  "strict": true, 
                                                                                  "skipLibCheck": true
                                                                                   }
                                                                                  }
                                                                                  

                                                                                  I have mongoose 6.02 installed in package.json and if it is of any help, I am getting mongo from dockerhub and running in a cluster pod.

                                                                                  Any help or suggestion is appreciated.

                                                                                  ANSWER

                                                                                  Answered 2021-Aug-29 at 08:36

                                                                                  ConnectOptions of mongoose for version 6.0.2 does not include useNewUrlParser, useUnifiedTopology, useCreateIndex. However, mongoose docs for 6.0.2 still shows those options to be valid and without those options, mongoose is throwing a topology error.

                                                                                  Downgraded mongoose to version 5.13.8 and now it is working without problems.

                                                                                  Source https://stackoverflow.com/questions/68970788

                                                                                  QUESTION

                                                                                  Why can't I use azure file share in my docker-compose to store mongodb data in Azure Container Instance?
                                                                                  Asked 2022-Feb-15 at 12:23

                                                                                  When using a docker ACI context, the following docker-compose file fails. The mongodb container continuously restarts.

                                                                                  version: "3.9"
                                                                                  
                                                                                  services:
                                                                                    mongodb:
                                                                                      image: mongo:5.0.6
                                                                                      env_file: mongo.env
                                                                                      environment:
                                                                                        - MONGO_INITDB_ROOT_USERNAME=root
                                                                                        - MONGO_INITDB_ROOT_PASSWORD=changeit
                                                                                      ports:
                                                                                        - 27017
                                                                                      volumes:
                                                                                        - dbdata:/data/db
                                                                                  
                                                                                  volumes:
                                                                                    dbdata:
                                                                                      driver: azure_file
                                                                                      driver_opts:
                                                                                        share_name: mongodb-data
                                                                                        storage_account_name: kpncoqyuxumoetuftz
                                                                                  

                                                                                  If I don't use the azure_file storage it will run ok (But of course the data won't be persistent)

                                                                                  ANSWER

                                                                                  Answered 2022-Feb-15 at 12:23

                                                                                  I am not sure why I can't mount to the default directory /data/db but to get this to work I had to mount to a different directory and then replace the default command with one that takes a parameter.

                                                                                  Working version is below:

                                                                                  version: "3.9"
                                                                                  
                                                                                  services:
                                                                                    mongodb:
                                                                                      image: mongo:5.0.6
                                                                                      command: ["mongod", "--dbpath=/dbdata"]
                                                                                      environment:
                                                                                        - MONGO_INITDB_ROOT_USERNAME=root
                                                                                        - MONGO_INITDB_ROOT_PASSWORD=changeit
                                                                                      ports:
                                                                                        - 27017
                                                                                      volumes:
                                                                                        - dbdata:/dbdata
                                                                                  
                                                                                  volumes:
                                                                                    dbdata:
                                                                                      driver: azure_file
                                                                                      driver_opts:
                                                                                        share_name: mongodb-data
                                                                                        storage_account_name: kpncoqyuxumoetuftz
                                                                                  
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71124410

                                                                                  QUESTION

                                                                                  react-query: useQuery returns undefined and component does not rerender
                                                                                  Asked 2022-Feb-07 at 03:17

                                                                                  I'm playing around with reactQuery in a little demo app you can see in this repo. The app calls this mock API.

                                                                                  I'm stuck on a an issue where I'm using the useQuery hook to call this function in a product API file:

                                                                                  export const getAllProducts = async (): Promise => {
                                                                                    const productEndPoint = 'http://localhost:5000/api/product';
                                                                                    const { data } = await axios.get(productEndPoint);
                                                                                    return data as Array;
                                                                                  };
                                                                                  

                                                                                  In my ProductTable component I then call this function using:

                                                                                  const { data } = useQuery('products', getAllProducts);
                                                                                  

                                                                                  I'm finding the call to the API does get made, and the data is returned. but the table in the grid is always empty.

                                                                                  If I debug I'm seeing the data object returned by useQuery is undefined.

                                                                                  The web request does successfully complete and I can see the data being returned in the network tab under requests in the browser.

                                                                                  I'm suspecting its the way the getAllProducts is structured perhaps or an async await issue but can't quite figure it out.

                                                                                  Can anyone suggest where IO may be going wrong please?

                                                                                  ANSWER

                                                                                  Answered 2021-Oct-14 at 18:24

                                                                                  I have managed to get this working. For the benefits of others ill share my learnings:

                                                                                  I made a few small changes starting with my api function. Changing the function to the following:

                                                                                  export const getAllProducts = async (): Promise => {
                                                                                     const response = await axios.get(`api/product`, {
                                                                                       headers: {
                                                                                         Accept: 'application/json',
                                                                                         'Content-Type': 'application/json',
                                                                                       },
                                                                                   });
                                                                                  
                                                                                    return response.data as Product[];
                                                                                  };
                                                                                  

                                                                                  I do not de-construct the response of the axios call but rather take the data object from it and return is as an Product[]

                                                                                  Then second thing I then changed was in my ProductTable component. Here I told useQuery which type of response to expect by changing the call to :

                                                                                  const { data } = useQuery('products', getAllProducts);
                                                                                  

                                                                                  Lastly, a rookie mistake on my part: because I was using a mock api in a docker container running on localhost and calling it using http://localhost:5000/api/product I was getting the all to well known network error:

                                                                                  localhost has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present...

                                                                                  So to get around that for the purpose of this exercise I just added a property to the packages.json file: "proxy":"http://localhost:5000",

                                                                                  This has now successfully allowed fetching of the data as I would expect it.

                                                                                  Source https://stackoverflow.com/questions/69549378

                                                                                  QUESTION

                                                                                  pymongo [SSL: CERTIFICATE_VERIFY_FAILED]: certificate has expired on Mongo Atlas
                                                                                  Asked 2022-Jan-29 at 22:03

                                                                                  I am using MongoDB(Mongo Atlas) in my Django app. All was working fine till yesterday. But today, when I ran the server, it is showing me the following error on console

                                                                                  Exception in thread django-main-thread:
                                                                                  Traceback (most recent call last):
                                                                                    File "c:\users\admin\appdata\local\programs\python\python39\lib\threading.py", line 973, in _bootstrap_inner
                                                                                      self.run()
                                                                                    File "c:\users\admin\appdata\local\programs\python\python39\lib\threading.py", line 910, in run
                                                                                      self._target(*self._args, **self._kwargs)
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
                                                                                      fn(*args, **kwargs)
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\core\management\commands\runserver.py", line 121, in inner_run
                                                                                      self.check_migrations()
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\core\management\base.py", line 486, in check_migrations
                                                                                      executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\db\migrations\executor.py", line 18, in __init__
                                                                                      self.loader = MigrationLoader(self.connection)
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\db\migrations\loader.py", line 53, in __init__
                                                                                      self.build_graph()
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\db\migrations\loader.py", line 220, in build_graph
                                                                                      self.applied_migrations = recorder.applied_migrations()
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\db\migrations\recorder.py", line 77, in applied_migrations
                                                                                      if self.has_table():
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\db\migrations\recorder.py", line 56, in has_table
                                                                                      tables = self.connection.introspection.table_names(cursor)
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\db\backends\base\introspection.py", line 52, in table_names
                                                                                      return get_names(cursor)
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\django\db\backends\base\introspection.py", line 47, in get_names
                                                                                      return sorted(ti.name for ti in self.get_table_list(cursor)
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\djongo\introspection.py", line 47, in get_table_list
                                                                                      for c in cursor.db_conn.list_collection_names()
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\pymongo\database.py", line 880, in list_collection_names
                                                                                      for result in self.list_collections(session=session, **kwargs)]
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\pymongo\database.py", line 842, in list_collections
                                                                                      return self.__client._retryable_read(
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\pymongo\mongo_client.py", line 1514, in _retryable_read
                                                                                      server = self._select_server(
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\pymongo\mongo_client.py", line 1346, in _select_server
                                                                                      server = topology.select_server(server_selector)
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\pymongo\topology.py", line 244, in select_server
                                                                                      return random.choice(self.select_servers(selector,
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\pymongo\topology.py", line 202, in select_servers
                                                                                      server_descriptions = self._select_servers_loop(
                                                                                    File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\Lib\site-packages\pymongo\topology.py", line 218, in _select_servers_loop
                                                                                      raise ServerSelectionTimeoutError(
                                                                                  pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-02.mny7y.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129),cluster0-shard-00-01.mny7y.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129),cluster0-shard-00-00.mny7y.mongodb.net:27017: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1129), Timeout: 30s, Topology Description: , , ]>
                                                                                  

                                                                                  I am using djongo as the database engine

                                                                                  DATABASES = {
                                                                                      'default': {
                                                                                              'ENGINE': 'djongo',
                                                                                              'NAME': 'DbName',
                                                                                              'ENFORCE_SCHEMA': False,
                                                                                              'CLIENT': {
                                                                                                  'host': 'mongodb+srv://username:password@cluster0.mny7y.mongodb.net/DbName?retryWrites=true&w=majority'
                                                                                              }  
                                                                                      }
                                                                                  }
                                                                                  

                                                                                  And following dependencies are being used in the app

                                                                                  dj-database-url==0.5.0
                                                                                  Django==3.2.5
                                                                                  djangorestframework==3.12.4
                                                                                  django-cors-headers==3.7.0
                                                                                  gunicorn==20.1.0
                                                                                  psycopg2==2.9.1
                                                                                  pytz==2021.1
                                                                                  whitenoise==5.3.0
                                                                                  djongo==1.3.6
                                                                                  dnspython==2.1.0
                                                                                  

                                                                                  What should be done in order to resolve this error?

                                                                                  ANSWER

                                                                                  Answered 2021-Oct-03 at 05:57

                                                                                  This is because of a root CA Let’s Encrypt uses (and Mongo Atals uses Let's Encrypt) has expired on 2020-09-30 - namely the "IdentTrust DST Root CA X3" one.

                                                                                  The fix is to manually install in the Windows certificate store the "ISRG Root X1" and "ISRG Root X2" root certificates, and the "Let’s Encrypt R3" intermediate one - link to their official site - https://letsencrypt.org/certificates/

                                                                                  Copy from the comments: download the .der field from the 1st category, download, double click and follow the wizard to install it.

                                                                                  Source https://stackoverflow.com/questions/69397039

                                                                                  QUESTION

                                                                                  angular 13: Module not found: Error: Can't resolve 'rxjs/operators'
                                                                                  Asked 2022-Jan-22 at 05:29

                                                                                  I have upgraded my angular to angular 13. when I run to build SSR it gives me following error.

                                                                                  ERROR in ./node_modules/@angular/common/fesm2015/http.mjs 12:0-56
                                                                                  Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/common/fesm2015'
                                                                                  Did you mean 'index.js'?
                                                                                  BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
                                                                                  (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
                                                                                  The extension in the request is mandatory for it to be fully specified.
                                                                                  Add the extension to the request.
                                                                                   @ ./src/app/app.server.module.ts 6:0-57 16:25-42
                                                                                   @ ./src/main.server.ts 3:0-58 3:0-58
                                                                                   @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
                                                                                  
                                                                                  ERROR in ./node_modules/@angular/core/fesm2015/core.mjs 8:0-39
                                                                                  Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/core/fesm2015'
                                                                                  Did you mean 'index.js'?
                                                                                  BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
                                                                                  (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
                                                                                  The extension in the request is mandatory for it to be fully specified.
                                                                                  Add the extension to the request.
                                                                                   @ ./server.ts 30:0-47 35:0-14
                                                                                  
                                                                                  ERROR in ./node_modules/@angular/forms/fesm2015/forms.mjs 11:0-37
                                                                                  Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/forms/fesm2015'
                                                                                  Did you mean 'index.js'?
                                                                                  BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
                                                                                  (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
                                                                                  The extension in the request is mandatory for it to be fully specified.
                                                                                  Add the extension to the request.
                                                                                   @ ./src/app/app.module.ts 12:0-45 78:12-23
                                                                                   @ ./src/app/app.server.module.ts 3:0-41 12:18-27
                                                                                   @ ./src/main.server.ts 3:0-58 3:0-58
                                                                                   @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
                                                                                  
                                                                                  ERROR in ./node_modules/@angular/platform-server/fesm2015/platform-server.mjs 21:0-39
                                                                                  Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/platform-server/fesm2015'
                                                                                  Did you mean 'index.js'?
                                                                                  BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
                                                                                  (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
                                                                                  The extension in the request is mandatory for it to be fully specified.
                                                                                  Add the extension to the request.
                                                                                   @ ./src/main.server.ts 4:0-77 4:0-77 4:0-77
                                                                                   @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
                                                                                  
                                                                                  ERROR in ./node_modules/@angular/router/fesm2015/router.mjs 10:0-180
                                                                                  Module not found: Error: Can't resolve 'rxjs/operators' in '/Users/nr/aws/jobsaf-website-staging/application/node_modules/@angular/router/fesm2015'
                                                                                  Did you mean 'index.js'?
                                                                                  BREAKING CHANGE: The request 'rxjs/operators' failed to resolve only because it was resolved as fully specified
                                                                                  (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
                                                                                  The extension in the request is mandatory for it to be fully specified.
                                                                                  Add the extension to the request.
                                                                                   @ ./src/app/app.component.ts 2:0-48 35:31-44
                                                                                   @ ./src/app/app.server.module.ts 2:0-47 13:20-32
                                                                                   @ ./src/main.server.ts 3:0-58 3:0-58
                                                                                   @ ./server.ts 32:0-52 40:15-30 44:0-34 44:0-34
                                                                                  

                                                                                  my package.json file:

                                                                                  {
                                                                                    "name": "admin-panel",
                                                                                    "version": "0.0.0",
                                                                                    "license": "MIT",
                                                                                    "angular-cli": {},
                                                                                    "scripts": {
                                                                                      "start": "DEBUG=jobsaf-website:* nodemon --inspect --trace-warnings --legacy-watch  --trace-warnings ./bin/www",
                                                                                      "seed": "node ./seeds/static-tables.js",
                                                                                      "test-jobsaf": "mocha --timeout 10000",
                                                                                      "rm-web": "rm -rf ./public/web/*",
                                                                                      "ng": "node ./node_modules/@angular/cli/bin/ng serve --host 0.0.0.0",
                                                                                      "ng:build": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng  build --configuration production --aot",
                                                                                      "build:server:prod": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng run jobsaf-website:server:prod && webpack --config webpack.server.config.js",
                                                                                      "build:browser:prod": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng build --configuration production --aot --vendor-chunk --deleteOutputPath=true --buildOptimizer  --progress=true",
                                                                                      "build:server:staging": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng run jobsaf-website:server:staging && webpack --config webpack.server.config.js",
                                                                                      "build:browser:staging": "node --max_old_space_size=4048 ./node_modules/@angular/cli/bin/ng build --configuration production --configuration=staging --aot --vendor-chunk --deleteOutputPath=true --buildOptimizer",
                                                                                      "build:stats": "node --max_old_space_size=3192 node_modules/@angular/cli/bin/ng build --configuration production --aot --vendor-chunk --deleteOutputPath=true --buildOptimizer  --progress=true --configuration production --stats-json",
                                                                                      "build:prod": "npm run rm-web && npm run build:server:prod && npm run build:browser:prod",
                                                                                      "build:staging": "npm run rm-web && npm run build:server:staging && npm run build:browser:staging",
                                                                                      "server": "node local.js",
                                                                                      "file:migration": "APP_FILE_MIGRATION=true node ./migration/file-migration.js",
                                                                                      "test_env": "set NODE_ENV=test",
                                                                                      "jest": "jest --detectOpenHandles --watchAll --config ./jest.config.js",
                                                                                      "coverage": "jest -i --coverage",
                                                                                      "jest:ci": "jest --detectOpenHandles --forceExit --config ./jest.config.js",
                                                                                      "test": "npm run test_env && npm run jest",
                                                                                      "test:ci": "npm run test_env && npm run seed && npm run jest:ci",
                                                                                      "dev:ssr": "ng run jobsaf-website:serve-ssr",
                                                                                      "serve:ssr": "node public/web/server/main.js",
                                                                                      "build:ssr": "ng build --configuration production && ng run jobsaf-website:server:prod",
                                                                                      "prerender": "ng run jobsaf-website:prerender",
                                                                                      "postinstall": "ngcc"
                                                                                    },
                                                                                    "private": true,
                                                                                    "napa": {
                                                                                      "jquery.flot.spline": "miloszfalinski/jquery.flot.spline",
                                                                                      "ika.jvectormap": "kakirigi/ika.jvectormap"
                                                                                    },
                                                                                    "dependencies": {
                                                                                      "@angular/animations": "^13.0.2",
                                                                                      "@angular/common": "^13.0.2",
                                                                                      "@angular/compiler": "^13.0.2",
                                                                                      "@angular/compiler-cli": "^13.0.2",
                                                                                      "@angular/core": "^13.0.2",
                                                                                      "@angular/forms": "^13.0.2",
                                                                                      "@angular/material": "^13.0.2",
                                                                                      "@angular/platform-browser": "^13.0.2",
                                                                                      "@angular/platform-browser-dynamic": "^13.0.2",
                                                                                      "@angular/platform-server": "^13.0.2",
                                                                                      "@angular/pwa": "^13.0.3",
                                                                                      "@angular/router": "^13.0.2",
                                                                                      "@angular/service-worker": "^13.0.2",
                                                                                      "@fortawesome/angular-fontawesome": "^0.10.1",
                                                                                      "@fortawesome/fontawesome-svg-core": "^1.2.36",
                                                                                      "@fortawesome/free-brands-svg-icons": "^5.15.4",
                                                                                      "@fortawesome/free-solid-svg-icons": "^5.15.4",
                                                                                      "@fullcalendar/core": "^5.10.1",
                                                                                      "@hapi/joi": "^15.1.0",
                                                                                      "@ng-select/ng-select": "^8.1.1",
                                                                                      "@nguniversal/common": "^13.0.1",
                                                                                      "@nguniversal/express-engine": "^13.0.1",
                                                                                      "@ngx-loading-bar/core": "^5.1.2",
                                                                                      "@ngxs/store": "^3.7.3-dev.master-1e7127b",
                                                                                      "@schematics/angular": "^13.0.3",
                                                                                      "@sindresorhus/slugify": "^1.1.0",
                                                                                      "@trademe/ng-defer-load": "^8.2.1",
                                                                                      "@types/jquery": "^3.5.8",
                                                                                      "angular-archwizard": "^7.0.0",
                                                                                      "angular2-uuid": "^1.1.1",
                                                                                      "apicache": "^1.6.3",
                                                                                      "archiver": "^5.3.0",
                                                                                      "aws-sdk": "^2.1031.0",
                                                                                      "bluebird": "^3.7.2",
                                                                                      "bootstrap": "5.1.3",
                                                                                      "compression": "^1.7.4",
                                                                                      "compromise": "^13.11.4",
                                                                                      "cookie-parser": "^1.4.6",
                                                                                      "core-js": "3.19.1",
                                                                                      "cors": "~2.8.5",
                                                                                      "debug": "^4.3.2",
                                                                                      "dotenv": "^10.0.0",
                                                                                      "easyimage": "^3.1.1",
                                                                                      "ejs": "^3.1.6",
                                                                                      "exceljs": "^4.3.0",
                                                                                      "express": "^4.17.1",
                                                                                      "express-jwt": "^6.1.0",
                                                                                      "express-mongo-sanitize": "^2.1.0",
                                                                                      "express-rate-limit": "^5.5.1",
                                                                                      "express-useragent": "^1.0.15",
                                                                                      "express-validator": "^6.13.0",
                                                                                      "feed": "^4.2.2",
                                                                                      "file-saver": "^2.0.5",
                                                                                      "firebase-admin": "^10.0.0",
                                                                                      "font-awesome": "^4.7.0",
                                                                                      "generate-password": "^1.7.0",
                                                                                      "google-auth-library": "^7.10.2",
                                                                                      "hammerjs": "^2.0.8",
                                                                                      "helmet": "^4.6.0",
                                                                                      "html-pdf": "^3.0.1",
                                                                                      "http-status": "^1.5.0",
                                                                                      "intl-tel-input": "^17.0.13",
                                                                                      "izitoast": "1.4.0",
                                                                                      "joi-objectid": "^4.0.2",
                                                                                      "jquery": "^3.6.0",
                                                                                      "jsonwebtoken": "^8.5.1",
                                                                                      "jwt-decode": "^3.1.2",
                                                                                      "keyword-extractor": "0.0.20",
                                                                                      "kickbox": "^2.0.4",
                                                                                      "libphonenumber-js": "^1.9.43",
                                                                                      "localstorage-polyfill": "^1.0.1",
                                                                                      "lodash": "^4.17.21",
                                                                                      "lodash.uniq": "^4.5.0",
                                                                                      "md5": "^2.3.0",
                                                                                      "moment": "^2.29.1",
                                                                                      "mongoose": "5.8.11",
                                                                                      "mongoose-history": "^0.8.0",
                                                                                      "mongoose-unique-validator": "^2.0.3",
                                                                                      "mongoose-url-slugs": "^1.0.2",
                                                                                      "multer": "^1.4.3",
                                                                                      "multer-s3": "^2.10.0",
                                                                                      "multer-s3-transform": "^2.10.3",
                                                                                      "mysql": "^2.18.1",
                                                                                      "ng-recaptcha": "^9.0.0",
                                                                                      "ng2-file-upload": "^1.4.0",
                                                                                      "ngx-auth": "^5.4.0",
                                                                                      "ngx-bootstrap": "^6.1.0",
                                                                                      "ngx-facebook": "^3.0.0-0",
                                                                                      "ngx-img-cropper": "^11.0.0",
                                                                                      "ngx-infinite-scroll": "^10.0.1",
                                                                                      "ngx-moment": "^5.0.0",
                                                                                      "ngx-pagination": "^5.1.1",
                                                                                      "ngx-quill-editor": "^2.2.2",
                                                                                      "ngx-toastr": "^14.2.0",
                                                                                      "node-schedule": "^2.0.0",
                                                                                      "nodemailer": "^6.7.1",
                                                                                      "passport": "^0.5.0",
                                                                                      "passport-facebook-token": "^4.0.0",
                                                                                      "passport-google-id-token": "^0.4.7",
                                                                                      "passport-google-token": "^0.1.2",
                                                                                      "passport-linkedin-token": "^0.1.1",
                                                                                      "passport-local": "^1.0.0",
                                                                                      "pdf-to-text": "0.0.7",
                                                                                      "phantomjs-prebuilt": "^2.1.16",
                                                                                      "phone": "^3.1.10",
                                                                                      "phpass": "^0.1.1",
                                                                                      "rand-token": "^1.0.1",
                                                                                      "request": "^2.88.2",
                                                                                      "request-ip": "^2.1.3",
                                                                                      "rxjs": "^6.5.5",
                                                                                      "sharp": "^0.29.3",
                                                                                      "showdown": "^1.9.1",
                                                                                      "simple-line-icons": "^2.5.5",
                                                                                      "socket.io": "^4.3.2",
                                                                                      "socket.io-client": "^4.3.2",
                                                                                      "socket.io-redis": "^5.4.0",
                                                                                      "socketio-auth": "^0.1.1",
                                                                                      "textract": "^2.5.0",
                                                                                      "ts-loader": "9.2.6",
                                                                                      "underscore": "^1.13.1",
                                                                                      "unique-random-array": "^2.0.0",
                                                                                      "url": "^0.11.0",
                                                                                      "util": "^0.12.4",
                                                                                      "uuid": "^8.3.2",
                                                                                      "winston": "^3.3.3",
                                                                                      "xlsx": "^0.17.4",
                                                                                      "xss-clean": "^0.1.1",
                                                                                      "zone.js": "~0.11.4",
                                                                                      "zxcvbn": "^4.4.2"
                                                                                    },
                                                                                    "devDependencies": {
                                                                                      "@angular-devkit/build-angular": "~13.0.3",
                                                                                      "@angular/cli": "^13.0.3",
                                                                                      "@types/express": "^4.17.13",
                                                                                      "@types/hammerjs": "^2.0.40",
                                                                                      "@types/mocha": "^9.0.0",
                                                                                      "@types/node": "^16.11.7",
                                                                                      "@types/underscore": "^1.11.3",
                                                                                      "husky": "^7.0.0",
                                                                                      "jasmine-core": "~3.10.1",
                                                                                      "jasmine-spec-reporter": "~7.0.0",
                                                                                      "jest": "^27.3.1",
                                                                                      "karma": "^6.3.9",
                                                                                      "karma-chrome-launcher": "~3.1.0",
                                                                                      "karma-coverage-istanbul-reporter": "^3.0.3",
                                                                                      "karma-jasmine": "~4.0.1",
                                                                                      "karma-jasmine-html-reporter": "^1.7.0",
                                                                                      "lint-staged": "^12.0.2",
                                                                                      "mocha": "^9.1.3",
                                                                                      "ng-diff-match-patch": "^3.0.1",
                                                                                      "nodemon": "^2.0.15",
                                                                                      "protractor": "^7.0.0",
                                                                                      "supertest": "^6.1.6",
                                                                                      "tslib": "^2.3.1",
                                                                                      "tslint": "^6.1.3",
                                                                                      "typescript": "4.4.3",
                                                                                      "webpack": "^5.64.1",
                                                                                      "webpack-cli": "^4.9.1"
                                                                                    }
                                                                                  }
                                                                                  
                                                                                  

                                                                                  Any Idea

                                                                                  ANSWER

                                                                                  Answered 2022-Jan-22 at 05:29

                                                                                  I just solve this issue by correcting the RxJS version to 7.4.0. I hope this can solve others issue as well.

                                                                                  Source https://stackoverflow.com/questions/70589846

                                                                                  QUESTION

                                                                                  Error: grid.mongo.GridStore is not a consstructor ,Using mongoose, Grid-fs-stream and grid multer storage
                                                                                  Asked 2022-Jan-19 at 04:43

                                                                                  I am getting the following error mentioned. The basic configs are as follow: I have uploaded the files on the server I want to download them but getting these errors I called a POST request to /api/files/delete/${fileId} Which should call the route and give back the file to the browser instead getting the error with the Grid related module.

                                                                                  MONGODB_CONNECTION_STRING = mongodb://localhost:27017/Cstore
                                                                                  
                                                                                  Db structure={Cstore:{uploads.files,uploads.chunks,users}}
                                                                                  
                                                                                  On requesting POST         axios.post(`/api/files/delete/${fileId}`)
                                                                                  
                                                                                  Getting error: 
                                                                                  
                                                                                       this._store = new grid.mongo.GridStore(grid.db, this.id || new grid.mongo.ObjectID(), this.name, this.mode, options);
                                                                                  [0]                 ^
                                                                                  [0] 
                                                                                  [0] TypeError: grid.mongo.GridStore is not a constructor
                                                                                  [0]     at new GridReadStream (/home/lenovo/Desktop/react/cstore/node_modules/gridfs-stream/lib/readstream.js:68:17)
                                                                                  
                                                                                  This is server.js
                                                                                  
                                                                                        app.get('/image/:filename', (req, res) => {
                                                                                      gfs.files.findOne({ 
                                                                                        _id: mongoose.Types.ObjectId(req.params.filename)
                                                                                        // filename: req.params.filename.toString()
                                                                                      }, (err, file) => {
                                                                                        // Check if file
                                                                                        if (!file || file.length === 0) {
                                                                                          console.log("not found")
                                                                                          return res.status(404).json({
                                                                                            
                                                                                            err: 'No file exists'
                                                                                          });
                                                                                        }
                                                                                  
                                                                                        // Check if image
                                                                                        if (file.contentType === 'image/jpeg' || file.contentType === 'image/png') {
                                                                                          // Read output to browser
                                                                                          console.log(file)
                                                                                          let id=file._id;
                                                                                  
                                                                                          const readStream = gfs.createReadStream(
                                                                                            {
                                                                                              _id: mongoose.Types.ObjectId(req.params.filename)
                                                                                            }
                                                                                            // {
                                                                                            // _id: id
                                                                                            // }
                                                                                          )
                                                                                          readStream.on('error', err => {
                                                                                              // report stream error
                                                                                              console.log(err);
                                                                                          });
                                                                                          // the response will be the file itself.
                                                                                          readStream.pipe(res);
                                                                                  
                                                                                        //   let readstream = gfs.createReadStream(mongoose.Types.ObjectId(file._id))
                                                                                        //   readstream.pipe(res)
                                                                                        // } else {
                                                                                          res.status(404).json({
                                                                                            err: 'Not an image'
                                                                                          });
                                                                                        }
                                                                                      });
                                                                                    });
                                                                                  
                                                                                  
                                                                                  
                                                                                    
                                                                                  
                                                                                      mongoose.Promise = global.Promise;
                                                                                        mongoose.connect(
                                                                                          mongoURI,
                                                                                          {
                                                                                            useNewUrlParser: true,
                                                                                            useUnifiedTopology: true,
                                                                                          },
                                                                                          (err) => {
                                                                                            if (err) throw err;
                                                                                            console.log('MongoDB connection established');
                                                                                          }
                                                                                        )
                                                                                        const connection = mongoose.connection;
                                                                                      
                                                                                        ///  HANDLING FILE
                                                                                        let gfs;
                                                                                        connection.once('open', () => {
                                                                                          // Init stream
                                                                                          gfs = Grid(connection.db, mongoose.mongo);
                                                                                          gfs.collection('uploads');
                                                                                        });
                                                                                      
                                                                                        const storage = new GridFsStorage({
                                                                                          url: mongoURI, 
                                                                                          file: (req, file) => {
                                                                                            return new Promise((resolve, reject) => {
                                                                                              crypto.randomBytes(16, (err, buf) => {
                                                                                                if (err) {
                                                                                                  return reject(err);
                                                                                                }
                                                                                                const filename = file.originalname;
                                                                                                const fileInfo = {
                                                                                                  filename: filename,
                                                                                                  bucketName: 'uploads'
                                                                                                };
                                                                                                resolve(fileInfo);
                                                                                              });
                                                                                            });
                                                                                          }
                                                                                        })
                                                                                      
                                                                                        const upload = multer({ storage });
                                                                                  
                                                                                  Initial:
                                                                                    const express = require('express');
                                                                                    const mongoose = require('mongoose');
                                                                                    const cookieParser = require('cookie-parser');
                                                                                    const path = require('path');
                                                                                  
                                                                                    const multer = require('multer');
                                                                                    const {GridFsStorage} = require('multer-gridfs-storage');
                                                                                    const Grid = require('gridfs-stream');
                                                                                    const methodOverride = require('method-override')
                                                                                    const crypto = require('crypto')
                                                                                  
                                                                                    const app = express();
                                                                                  
                                                                                    app.use(express.json());
                                                                                    app.use(express.urlencoded({ extended: true }));
                                                                                    app.use(methodOverride('_method'));
                                                                                    app.use(cookieParser());
                                                                                  
                                                                                    const dotenv=require('dotenv');
                                                                                    dotenv.config({path:__dirname+'/.env'});
                                                                                  
                                                                                    const mongoURI = process.env.MONGODB_CONNECTION_STRING
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Sep-07 at 04:57

                                                                                  I also faced similar issues. The resolution for me was with mongoose version. The issue arises in the version 6.0.5 but is working in the version 5.13.7

                                                                                  Source https://stackoverflow.com/questions/69055292

                                                                                  QUESTION

                                                                                  @EnableAutoConfiguration(exclude =...) on tests failed in Spring Boot 2.6.0
                                                                                  Asked 2022-Jan-15 at 03:04

                                                                                  I tried to upgrade my data-mongo example project to Spring Boot 2.6.0. There is a test designed to run against Testcontainers, I also included the embedded mongo dep for other tests, so I have to exclude the AutoConfiguration for embedded mongo to make sure this test working on Docker/testcontainers.

                                                                                  The following configuration worked well with Spring Boot 2.5.6.

                                                                                  
                                                                                  @DataMongoTest
                                                                                  @ContextConfiguration(initializers = {MongodbContainerInitializer.class})
                                                                                  @EnableAutoConfiguration(exclude = EmbeddedMongoAutoConfiguration.class)
                                                                                  @Slf4j
                                                                                  @ActiveProfiles("test")
                                                                                  public class PostRepositoryTest {}
                                                                                  

                                                                                  But after upgrading to Spring Boot 2.6.0 and running the application, I got the exception like this.

                                                                                  [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: o
                                                                                  rg.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'embeddedMongoServer' defined in class path resource [org/springframework/boot/autoconfig
                                                                                  ure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: Unsatisfied dependency expressed through method 'embeddedMongoServer' parameter 0; nested exception is org.springframework.bea
                                                                                  ns.factory.BeanCreationException: Error creating bean with name 'embeddedMongoConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/Embed
                                                                                  dedMongoAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.flap
                                                                                  doodle.embed.mongo.config.MongodConfig]: Factory method 'embeddedMongoConfiguration' threw exception; nested exception is java.lang.IllegalStateException: Set the spring.mongodb.embedd
                                                                                  ed.version property or define your own MongodConfig bean to use embedded MongoDB
                                                                                  

                                                                                  Obviously, @EnableAutoConfiguration(exclude =...) did not affect the context in tests when upgrading to Spring Boot 2.6.0.

                                                                                  Update: Temporarily resolved it, see my answer below.

                                                                                  ANSWER

                                                                                  Answered 2021-Nov-20 at 17:20

                                                                                  As of Spring Boot 2.6, the property spring.mongodb.embedded.version must be set to use the auto-configured embedded MongoDB. It's mentioned in the release notes: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6-Release-Notes#embedded-mongo

                                                                                  This is also what the error message you posted, advises to do: Set the spring.mongodb.embedd ed.version property or define your own MongodConfig bean to use embedded MongoDB

                                                                                  The annotation @DataMongoTest is meta-annotated with @ImportAutoConfiguration and @AutoConfigureDataMongo, and is designed to trigger auto-configuration of MongoDB unless explicitly disabled as you do in the working configuration examples.

                                                                                  In your first configuration example, the annotation @EnableAutoConfiguration(exclude = EmbeddedMongoAutoConfiguration.class) does not override this effect of @DataMongoTest.

                                                                                  With Spring Boot 2.5.6, the auto-configured MongodConfig bean is most likely also part of the application context but not effectively used. But this depends on the rest of the code and in particular on the MongodbContainerInitializer.

                                                                                  Source https://stackoverflow.com/questions/70047380

                                                                                  QUESTION

                                                                                  How do I connect to MongoDB, running in Github codespaces, using MongoDB Compass?
                                                                                  Asked 2022-Jan-09 at 23:27

                                                                                  I'm trying out Github codespaces, specifically the "Node.js & Mongo DB" default settings.

                                                                                  The port is forwarded, and my objective is to connect with MongoDB Compass running on my local machine.

                                                                                  The address forwarded to 27017 is something like https://.githubpreview.dev/

                                                                                  My attempt

                                                                                  I attempted to use the following connection string, but it did not work in MongoDB compass. It failed with No addresses found at host. I'm actually unsure about how I even determine if MongoDB is actually running in the Github codespace?

                                                                                  mongodb+srv://root:example@.githubpreview.dev/
                                                                                  
                                                                                  .devcontainer files

                                                                                  docker-compose.yml

                                                                                  version: '3.8'
                                                                                  
                                                                                  services:
                                                                                    app:
                                                                                      build:
                                                                                        context: .
                                                                                        dockerfile: Dockerfile
                                                                                        args:
                                                                                          # Update 'VARIANT' to pick an LTS version of Node.js: 16, 14, 12.
                                                                                          # Append -bullseye or -buster to pin to an OS version.
                                                                                          # Use -bullseye variants on local arm64/Apple Silicon.
                                                                                          VARIANT: "16"
                                                                                      volumes:
                                                                                        - ..:/workspace:cached
                                                                                      init: true
                                                                                  
                                                                                      # Overrides default command so things don't shut down after the process ends.
                                                                                      command: sleep infinity
                                                                                  
                                                                                      # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
                                                                                      network_mode: service:db
                                                                                      # Uncomment the next line to use a non-root user for all processes.
                                                                                      # user: node
                                                                                  
                                                                                      # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. 
                                                                                      # (Adding the "ports" property to this file will not forward from a Codespace.)
                                                                                  
                                                                                    db:
                                                                                      image: mongo:latest
                                                                                      restart: unless-stopped
                                                                                      volumes:
                                                                                        - mongodb-data:/data/db
                                                                                      # Uncomment to change startup options
                                                                                      environment:
                                                                                       MONGO_INITDB_ROOT_USERNAME: root
                                                                                       MONGO_INITDB_ROOT_PASSWORD: example
                                                                                       MONGO_INITDB_DATABASE: foo
                                                                                  
                                                                                      # Add "forwardPorts": ["27017"] to **devcontainer.json** to forward MongoDB locally.
                                                                                      # (Adding the "ports" property to this file will not forward from a Codespace.)
                                                                                  
                                                                                  volumes:
                                                                                    mongodb-data: null
                                                                                  
                                                                                  

                                                                                  And a devcontainer.json file

                                                                                  // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
                                                                                  // https://github.com/microsoft/vscode-dev-containers/tree/v0.203.0/containers/javascript-node-mongo
                                                                                  // Update the VARIANT arg in docker-compose.yml to pick a Node.js version
                                                                                  {
                                                                                      "name": "Node.js & Mongo DB",
                                                                                      "dockerComposeFile": "docker-compose.yml",
                                                                                      "service": "app",
                                                                                      "workspaceFolder": "/workspace",
                                                                                  
                                                                                      // Set *default* container specific settings.json values on container create.
                                                                                      "settings": {},
                                                                                  
                                                                                      // Add the IDs of extensions you want installed when the container is created.
                                                                                      "extensions": [
                                                                                          "dbaeumer.vscode-eslint",
                                                                                          "mongodb.mongodb-vscode" 
                                                                                      ],
                                                                                  
                                                                                      // Use 'forwardPorts' to make a list of ports inside the container available locally.
                                                                                      "forwardPorts": [3000, 27017],
                                                                                  
                                                                                      // Use 'postCreateCommand' to run commands after the container is created.
                                                                                      // "postCreateCommand": "yarn install",
                                                                                  
                                                                                      // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
                                                                                      "remoteUser": "node",
                                                                                      "features": {
                                                                                          "git": "os-provided"
                                                                                      }
                                                                                  }
                                                                                  

                                                                                  and finally a Docker file:

                                                                                  # [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
                                                                                  ARG VARIANT=16-bullseye
                                                                                  FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
                                                                                  
                                                                                  # Install MongoDB command line tools if on buster and x86_64 (arm64 not supported)
                                                                                  ARG MONGO_TOOLS_VERSION=5.0
                                                                                  RUN . /etc/os-release \
                                                                                      && if [ "${VERSION_CODENAME}" = "buster" ] && [ "$(dpkg --print-architecture)" = "amd64" ]; then \
                                                                                          curl -sSL "https://www.mongodb.org/static/pgp/server-${MONGO_TOOLS_VERSION}.asc" | gpg --dearmor > /usr/share/keyrings/mongodb-archive-keyring.gpg \
                                                                                          && echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mongodb-archive-keyring.gpg] http://repo.mongodb.org/apt/debian $(lsb_release -cs)/mongodb-org/${MONGO_TOOLS_VERSION} main" | tee /etc/apt/sources.list.d/mongodb-org-${MONGO_TOOLS_VERSION}.list \
                                                                                          && apt-get update && export DEBIAN_FRONTEND=noninteractive \
                                                                                          && apt-get install -y mongodb-database-tools mongodb-mongosh \
                                                                                          && apt-get clean -y && rm -rf /var/lib/apt/lists/*; \
                                                                                      fi
                                                                                  
                                                                                  # [Optional] Uncomment this section to install additional OS packages.
                                                                                  # RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
                                                                                  #     && apt-get -y install --no-install-recommends 
                                                                                  
                                                                                  # [Optional] Uncomment if you want to install an additional version of node using nvm
                                                                                  # ARG EXTRA_NODE_VERSION=10
                                                                                  # RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
                                                                                  
                                                                                  # [Optional] Uncomment if you want to install more global node modules
                                                                                  # RUN su node -c "npm install -g "
                                                                                  

                                                                                  Update I also posted here in the MongoDB community, but no help...

                                                                                  ANSWER

                                                                                  Answered 2022-Jan-09 at 23:27

                                                                                  As @iravinandan said you need to set up a tunnel.

                                                                                  Publishing a port alone won't help as all incoming requests are going through an http proxy.

                                                                                  If you dig CNAME .githubpreview.dev you will see it's github-codespaces.app.online.visualstudio.com. You can put anything in the githubpreview.dev subdomain and it will still be resolved on the DNS level.

                                                                                  The proxy relies on HTTP Host header to route the request to correct upstream so it will work for HTTP protocols only.

                                                                                  To use any other protocol (MongoDb wire protocol in your case) you need to set up a TCP tunnel from codespaces to your machine.

                                                                                  Simplest set up - direct connection

                                                                                  At the time of writing the default Node + Mongo codespace uses Debian buster, so ssh port forwarding would be the obvious choice. In the codespace/VSCode terminal:

                                                                                  ssh -R 27017:localhost:27017 your_public_ip
                                                                                  

                                                                                  Then in your compas connect to

                                                                                  mongodb://localhost:27017
                                                                                  

                                                                                  It will require your local machine to run sshd of course, have a white IP (or at least your router should forward incoming ssh traffic to your computer) and allow it in the firewall. You can pick any port if 27017 is already being used locally.

                                                                                  It's the simplest set up but it exposes your laptop to the internet, and it's just a matter of time to get it infected.

                                                                                  A bit more secure - jumpbox in the middle

                                                                                  To keep your local system behind DMZ you can set up a jumpbox instead - a minimalistic disposable linux box somewhere in the internet, which will be used to chain 2 tunnels:

                                                                                  • Remote port forwarding from codespace to the jumpbox
                                                                                  • Local port forwarding from your laptop to the jumpbox

                                                                                  The same

                                                                                  mongodb://localhost:27017
                                                                                  

                                                                                  on mongo compas.

                                                                                  The jumpbox have to expose sshd to the internet, but you can minimise risks by hardening its security. After all it doesn't do anything but proxy traffic. EC2 nano will be more than enough, just keep in mind large data transfers might be expensive.

                                                                                  Hassle-free tunnel-as-a-service

                                                                                  Something you can try in 5 min. ngrok has been around for more than a decade and it does exactly this - it sells tunnels (with some free tier sufficient for the demo).

                                                                                  In your codespace/VScode terminal:

                                                                                  npm i ngrok --save-dev
                                                                                  

                                                                                  To avoid installing every time but ensure you don't ship with production code. You will need to register an account on ngrok (SSO with github will do) to get an authentication code and pass it to the codespaces/VSCode terminal:

                                                                                  ./node_modules/.bin/ngrok authtoken 
                                                                                  

                                                                                  Please remember it saves the token to the home directory which will be wiped after rebuild. Once authorised you can open the tunnel in the codespaces/VSCode terminal:

                                                                                  ./node_modules/.bin/ngrok tcp 27017
                                                                                  

                                                                                  Codespace will automatically forward the port:

                                                                                  And the terminal will show you some stats (mind the free tier limit) and connection string:

                                                                                  The subdomain and port will change every time you open the tunnel. From the image above the connection parameters for mongodb compas will be:

                                                                                  mongodb://0.tcp.ngrok.io:18862
                                                                                  

                                                                                  with authorization parameters on mongodb level as needed.

                                                                                  Again, keep in mind you leave your mongodb exposed to the internet (0.tcp.ngrok.io:18862), and mongo accepts unauthenticated connections.

                                                                                  I wouldn't leave it open for longer than necessary.

                                                                                  Use built-in mongodb client

                                                                                  The node + mongo environment comes with handy VScode plugins pre-installed:

                                                                                  Of course it lacks many of compas analytical tools but it works out of the box and is sufficient for development.

                                                                                  Just open the plugin and connect to localhost:

                                                                                  Compass D.I.Y

                                                                                  The best option to get compass functionality without compromising security and achieve zero-config objective is to host compass yourself. It's an electron application and works perfectly in a browser in Mongodb Atlas.

                                                                                  The source code is available at https://github.com/mongodb-js/compass. With a bit of effort you can craft a docker image to host compass, include this image into docker-compose, and forward the port in devcontainer.json

                                                                                  Github codespaces will take care of authentication (keep the forwarded port private so only owner of the space will have access to it). All communication from desktop to compass will be over https, and compass to mongodb will be local to the docker network. Security-wise it will be on par with VSCode mongodb plugin

                                                                                  Source https://stackoverflow.com/questions/70296667

                                                                                  QUESTION

                                                                                  mongodb unable establish remote cursors
                                                                                  Asked 2021-Dec-02 at 15:52

                                                                                  Anybody seen this messages before in mongodb sharded cluster 4.0.16 mongos during balancing:

                                                                                     2021-10-24T13:26:03.723+0200 I QUERY    [conn636] Unable to establish remote cursors - {error: StaleConfig{ ns: "prod.assests", vReceived: Timestamp(1841827, 4), vReceivedEpoch: ObjectId('584af7e7cec9edde8118d5ac'), vWanted: Timestamp(1841826, 1), vWantedEpoch: ObjectId('584af7e7cec9edde8118d5ac') }: version mismatch detected for prod.assests, numActiveRemotes: 0}
                                                                                     2021-10-24T13:26:03.723+0200 I QUERY    [conn768] Unable to establish remote cursors - {error: StaleConfig{ ns: "prod.assests", vReceived: Timestamp(1841827, 4), vReceivedEpoch: ObjectId('584af7e7cec9edde8118d5ac'), vWanted: Timestamp(1841826, 1), vWantedEpoch: ObjectId('584af7e7cec9edde8118d5ac') }: version mismatch detected for prod.assests, numActiveRemotes: 0}
                                                                                     2021-10-24T13:26:03.723+0200 I QUERY    [conn507] Unable to establish remote cursors - {error: StaleConfig{ ns: "prod.assests", vReceived: Timestamp(1841827, 4), vReceivedEpoch: ObjectId('584af7e7cec9edde8118d5ac'), vWanted: Timestamp(1841826, 1), vWantedEpoch: ObjectId('584af7e7cec9edde8118d5ac') }: version mismatch detected for prod.assests, numActiveRemotes: 4}
                                                                                  

                                                                                  This messages appear only during balancing in a 5x shards (1TB on ssd each) cluster in all mongoses... Also messages appear only during the mentioned collection balancing , other collections balance with no such messages in same cluster...

                                                                                  The questions:

                                                                                  1.Any advice will be highly appreciated on why this messages appear?

                                                                                  2.What is the meaning of this message, do I need to worry about ?

                                                                                  1. Is there possible fix?

                                                                                  Balancing seems working correctly ...

                                                                                  Customers not complaining , queries to cluster working correctly ...

                                                                                  RangeDeleter working correctly ....

                                                                                  There is no network or storage resources issues ...

                                                                                  The load is minimal during the time of balancing ...

                                                                                  ANSWER

                                                                                  Answered 2021-Dec-02 at 15:52
                                                                                  1. This message is expected behaviour during balancing when there is read request for documents already migrated to other shard.
                                                                                  2. The meaning is that the mongos is not able to establish remote cursor to the old shard since the config is reported stale and data is moved to the new shard.
                                                                                  3. No fix is necessary this is informative message only.

                                                                                  Source https://stackoverflow.com/questions/69699723

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install mongo

                                                                                  You can download it from GitHub.

                                                                                  Support

                                                                                  For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit
                                                                                  CLONE
                                                                                • HTTPS

                                                                                  https://github.com/mongodb/mongo.git

                                                                                • CLI

                                                                                  gh repo clone mongodb/mongo

                                                                                • sshUrl

                                                                                  git@github.com:mongodb/mongo.git

                                                                                • Share this Page

                                                                                  share link

                                                                                  Explore Related Topics

                                                                                  Reuse Pre-built Kits with mongo

                                                                                  Consider Popular Database Libraries

                                                                                  redis

                                                                                  by redis

                                                                                  tidb

                                                                                  by pingcap

                                                                                  rethinkdb

                                                                                  by rethinkdb

                                                                                  cockroach

                                                                                  by cockroachdb

                                                                                  ClickHouse

                                                                                  by ClickHouse

                                                                                  Try Top Libraries by mongodb

                                                                                  node-mongodb-native

                                                                                  by mongodbTypeScript

                                                                                  mongo-go-driver

                                                                                  by mongodbGo

                                                                                  mongoid

                                                                                  by mongodbRuby

                                                                                  mongo-python-driver

                                                                                  by mongodbPython

                                                                                  Compare Database Libraries with Highest Support

                                                                                  tidb

                                                                                  by pingcap

                                                                                  redis

                                                                                  by redis

                                                                                  ClickHouse

                                                                                  by ClickHouse

                                                                                  liquibase

                                                                                  by liquibase

                                                                                  rocksdb

                                                                                  by facebook

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit