Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Connect with Mongo Cluster #63

Open
devalexanderdaza opened this issue Apr 25, 2020 · 1 comment
Open

Connect with Mongo Cluster #63

devalexanderdaza opened this issue Apr 25, 2020 · 1 comment

Comments

@devalexanderdaza
Copy link

Hi!

How connect nodefony with Mongo Atlas Cluster? Thanks :)

@ccamensuli
Copy link
Member

hi Alexender,

Sorry for the lack of documentation !!

To Configure mongodb/mongoose  project :

Add bundle core mongoose in kernel configuration file

./config/config.js

   * ENGINE ORM
   *       sequelize || mongoose
   *   orm : mongoose
   */
  orm: "mongoose"

Overload mongoose-bundle in configuration file

./app/config/nondefony/mongoose-bundle.js

configure connection domain ...

 *   OVERRIDE ORM BUNDLE MONGOOSE
 *
 *       @see MONGOOSE BUNDLE config for more options
 *       @more options https://mongoosejs.com/docs/connections.html
 *
 *       By default nodefony create connector name nodefony
 *       for manage Sessions / Users
 */
module.exports = {
  debug: false,
  connectors: {
    nodefony: {
      host: "localhost",
      port: 27017,
      dbname: "nodefony",
      settings: {
        user: "",
        pass: "",
        authSource: "admin",
        reconnectTries: 100,
        reconnectInterval: 5000,
        autoReconnect: true,
        poolSize: 5
      }
    }
  }
}

To create mongodb project you can use Nodefony CLI

Install Nodefony

npm -g install nodefony

# or with yarn

yarn global add nodefony

Install Project with cli

$ npx nodefony

              _   _    ___    ____    _____   _____    ___    _   _  __   __
             | \ | |  / _ \  |  _ \  | ____| |  ___|  / _ \  | \ | | \ \ / /
             |  \| | | | | | | | | | |  _|   | |_    | | | | |  \| |  \ V / 
             | |\  | | |_| | | |_| | | |___  |  _|   | |_| | | |\  |   | |  
             |_| \_|  \___/  |____/  |_____| |_|      \___/  |_| \_|   |_|  
                                                                            

                                                                                                                                                                                                                
          Version : 6.0.0-beta.8   Platform : darwin   Process : nodefony   Pid : 14597

 Sat Apr 25 2020 21:20:19 INFO nodefony : WELCOME NODEFONY CLI 6.0.0-beta.8
?  Nodefony CLI :  Create Nodefony Web Project
? Enter Nodefony Project Name nodefony-starter
? Enter short description Project Description
? Choose Project Application Type (Mapping Front Framework in App) : Sandbox (without Front framwork)
? Project Path /Users/christophecamensuli/repository/test
? Please Enter Author Full Name admin
? Please Enter Email Author  [email protected]
? Enter Server Domain : 0.0.0.0
? Enter server Domain http Port  : 5151
? Enter Server Secure Domain https Port  : 5152
? Choose default ORM  (Mapping Objet Relationnel) : 
  sequelize 
❯ mongoose 

After install if mongodb don't run on loopback (127.0.0.1)

Sat Apr 25 2020 21:33:57 ERROR mongoose  : Cannot connect to mongodb ( 127.0.0.1:27017/nodefony )
 Sat Apr 25 2020 21:33:57 ERROR mongoose  : failed to connect to server [127.0.0.1:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017

Just Overload config in ./app/config/nondefony/mongoose-bundle.js

$ npx nodefony dev

....
 Sat Apr 25 2020 21:36:45 INFO mongoose  :  REGISTER ENTITY : requests PROVIDE BUNDLE : mongoose
 Sat Apr 25 2020 21:36:45 INFO mongoose  :  REGISTER ENTITY : session PROVIDE BUNDLE : mongoose
 Sat Apr 25 2020 21:36:45 INFO mongoose  :  REGISTER ENTITY : jwt PROVIDE BUNDLE : security
 Sat Apr 25 2020 21:36:45 INFO EVENTS mongoose ORM : onOrmReady
 Sat Apr 25 2020 21:36:45 INFO mongoose  : ORM CONNECTORS LIST  : 
┌───────────────────────────┬───────────────┬─────────┬─────────────────┐
│ MONGOOSE CONNECTIONS NAME │ NAME DATABASE │ DRIVER  │ URI             │
├───────────────────────────┼───────────────┼─────────┼─────────────────┤
│ nodefony                  │ nodefony      │ mongodb │ 127.0.0.1:27017 │
└───────────────────────────┴───────────────┴─────────┴─────────────────┘

You can @see code in users-bundle for an implementation of mongoose Entity and controller

https://github.com/nodefony/nodefony-core/tree/master/src/nodefony/cli/builder/bundles/users-bundle

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

No branches or pull requests

2 participants