apostrophecms / apostrophe

A full-featured, open-source content management framework built with Node.js that empowers organizations by combining in-context editing and headless architecture in a full-stack JS environment.
https://apostrophecms.com
MIT License
4.36k stars 590 forks source link

Where is the database connection? MongoError: command find requires authentication #3511

Open RobertSandiford opened 3 years ago

RobertSandiford commented 3 years ago

I'm really baffled with the setup of this app.

I followed the instructions here, using the CLI method. https://v3.docs.apostrophecms.org/guide/setting-up.html#creating-a-project

Different to the guide, it installed packages itself, and seemingly create an admin user without prompting.

Then when I yarn dev I get "MongoError: command find requires authentication"

And it occurs to me that there was no mention anywhere of putting in database details.

I'm figuring that these docs are badly out of date. What's the state of affairs? Is the project still going?

Version of Node.js: v14.8.1

Version of MongDB: v4.4.3

Server Operating System: Win 10

zenflow commented 3 years ago

@RobertSandiford Try running with this env var: APOS_MONGODB_URI=mongodb://localhost/<db name>?authSource=admin (replace <db name>)

I started with this boilerplate a week ago and didn't have any problem connecting to local db but when it came time to connect to my prod db I had a problem like this and had to add ?authSource=admin to my connection string.

This problem might be related to mongodb server configuration or version.

RobertSandiford commented 3 years ago

Nope that hasn't fixed it. My string works in MongoDB Compass but no change in apostrophe.

https://github.com/apostrophecms/a3-boilerplate

The boilerplate here also doesn't have an .env or any instructions on making an .env or entering database details. So this is still quite weird to me.

RobertSandiford commented 3 years ago

Ah you mean setting a shell env variable (or whatever it's called). I guess it will just hook up .dotenv.

Thanks

RobertSandiford commented 3 years ago

Here is an updated repo with .env, dotenv, cross-env (needed to run on windows), and updated readme, if apos want to use it.

https://github.com/RobertSandiford/a3-boilerplate

RobertSandiford commented 3 years ago

I get missing styles after build.

I guess this is just not being maintained, sadly.

:3000/apos-frontend/…module-bundle.js:85 Uncaught Error: Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/dist/cjs.js): Error: PostCSS plugin autoprefixer requires PostCSS 8. Migration guide for end-users: https://github.com/postcss/postcss/wiki/PostCSS-8-for-end-users at Processor.normalize (C:\Users\Robert\Desktop\apostrophe\node_modules\postcss\lib\processor.js:153:15) at new Processor (C:\Users\Robert\Desktop\apostrophe\node_modules\postcss\lib\processor.js:56:25) at postcss (C:\Users\Robert\Desktop\apostrophe\node_modules\postcss\lib\postcss.js:55:10) at Object.loader (C:\Users\Robert\Desktop\apostrophe\node_modules\postcss-loader\dist\index.js:87:20) at processResult (C:\Users\Robert\Desktop\apostrophe\node_modules\webpack\lib\NormalModule.js:701:19) at C:\Users\Robert\Desktop\apostrophe\node_modules\webpack\lib\NormalModule.js:807:5 at C:\Users\Robert\Desktop\apostrophe\node_modules\loader-runner\lib\LoaderRunner.js:399:11 at C:\Users\Robert\Desktop\apostrophe\node_modules\loader-runner\lib\LoaderRunner.js:251:18 at context.callback (C:\Users\Robert\Desktop\apostrophe\node_modules\loader-runner\lib\LoaderRunner.js:124:13) at Object.loader (C:\Users\Robert\Desktop\apostrophe\node_modules\postcss-loader\dist\index.js:96:7) at Object../modules/asset/ui/src/index.scss (http://localhost:3000/apos-frontend/default/apos-module-bundle.js:85:7) at webpack_require (http://localhost:3000/apos-frontend/default/apos-module-bundle.js:109:41) at eval (webpack-internal:///./apos-build/default/src-import.js:5:123) at Object../apos-build/default/src-import.js (http://localhost:3000/apos-frontend/default/apos-module-bundle.js:20:1) at webpack_require (http://localhost:3000/apos-frontend/default/apos-module-bundle.js:109:41) at http://localhost:3000/apos-frontend/default/apos-module-bundle.js:161:37 at http://localhost:3000/apos-frontend/default/apos-module-bundle.js:163:12

zenflow commented 3 years ago

@RobertSandiford Are you using Yarn package manager or npm?

If it's Yarn, try npm instead. I had a similar problem.

zenflow commented 3 years ago

Here is an updated repo with .env, dotenv, cross-env (needed to run on windows), and updated readme, if apos want to use it.

https://github.com/RobertSandiford/a3-boilerplate

@RobertSandiford I would go for a PR! Having this stuff set up in the boilerplate already is definitely useful.

RobertSandiford commented 3 years ago

Well isn't that funny. Delete node_modules and reinstalled with npm and it works! Still get the error, but the styles are there.

Thank you!

RobertSandiford commented 3 years ago

Actually maybe no error - just had preserve log on

boutell commented 3 years ago

@abea this is a good reminder that not everyone is in an environment where even local mongodb does not require credentials, would you mind considering this a ticket to document APOS_MONGODB_URI?

boutell commented 3 years ago

(Or rather, to mention it at the necessary steps early enough that developers don't stub their toes before they get a chance to really try Apostrophe)

abea commented 3 years ago

I'll create a ticket in our internal system to follow up.

whyayala commented 1 year ago

Old issue, but I ran into the same problem. In mycase, I was standing up my mongodb instance in a container defined in a docker-compose.yml file with the default user/password set as follows:

      - MONGO_INITDB_ROOT_USERNAME=rootuser
      - MONGO_INITDB_ROOT_PASSWORD=rootpassword

From there, I passed the connection string as an env variable to the create script: APOS_MONGODB_URI=mongodb://rootuser:rootpassword@127.0.0.1:27017/?authMechanism=DEFAULT apos create my-blog

And the create script ran successfully without errors.

Another thing I'd like to propose is that since this has a dependency on node and mongodb, the create script should be able to run on an existing non-empty folder. In my case, I stood up mongodb with docker compose and am managing my node installation with nvm. I put a docker-compose.yml file in my project root, along with a .nvm file to declare my node version. Was surprised to find the create script would fail immediately when I had these defined in an existing folder.

While I was able to create these files and stand up the mongodb service outside of my project root and move them into the folder afterwords, that feels counter-intuitive.