简体   繁体   English

节点填充 b url 不起作用

[英]node populatedb url not working

I am learning ExpressJs tutorial from https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose我正在从https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose学习 ExpressJs 教程

Now I have created module for mongodb database and then create a file populatedb.js in the root directory.现在我已经为 mongodb 数据库创建了模块,然后在根目录中创建了一个文件填充 b.js。 Now I am trying to connect to database using command (as describe at last on above link)现在我正在尝试使用命令连接到数据库(最后在上面的链接中描述)

node populatedb mongodb://dbuser:dbpassword@ds133814.mlab.com:33814/local_library_tutorial

but terminal response nothing and there doesn't happen in database但终端没有响应,数据库中也没有发生

My Brother.我的兄弟。

I ran into the same problem, and when my search led me to your question i was even more sad when I saw no answer, however after searching around, I found an answer!我遇到了同样的问题,当我的搜索将我引向您的问题时,当我没有看到答案时,我更加难过,但是在四处寻找之后,我找到了答案!

  1. Make sure you replace the "dbuser:dbpassword" placeholders with actual data eg "Elias:js44889" on your mongo url.确保将“dbuser:dbpassword”占位符替换为实际数据,例如 mongo url 上的“Elias:js44889”。

  2. Also just make sure it's also the same as the one in app.js.还要确保它也与 app.js 中的相同。

I think all should be fine as it was for me.我认为一切都应该很好,就像对我一样。

you must include the script in populatedb.js to get work done.您必须在populatedb.js 中包含脚本才能完成工作。

populatedb.js script link : https://raw.githubusercontent.com/hamishwillee/express-locallibrary-tutorial/master/populatedb.js populatedb.js 脚本链接: https : //raw.githubusercontent.com/hamishwillee/express-locallibrary-tutorial/master/populatedb.js

After inserting the script in populatedb.js file from above link, then run the following commands to populate data in mongoDB.从上面的链接将脚本插入到populatedb.js 文件中后,然后运行以下命令在mongoDB 中填充数据。

npm install async (if not installed async module) npm install async (如果没有安装 async 模块)

node populatedb <your mongodb url>

sometimes you may get an error if you use the same collection name in all of your models, this happened to me until i realised what i was doing was wrong.有时,如果您在所有模型中使用相同的集合名称,可能会出现错误,这发生在我身上,直到我意识到我所做的是错误的。

for example don't do this例如不要这样做

const authorModel = mongoose.model('author', AuthorSchema)
const bookModel = mongoose.model('author', BookSchema)

if you do it un-expeectedly it will throw this error如果你意外地这样做,它会抛出这个错误
OverwriteModelError: Cannot overwrite author model once compiled.

instead in the commandline for "windows users" write而是在“Windows 用户”的命令行中写入

node populatedb mongodb+srv://username:password@yourcluster.mongodb.net/yourdatabase

and in your models make sure that the collections are not the same并在您的模型中确保集合不同

const authorModel = mongoose.model('author', AuthorSchema)
const bookModel = mongoose.model('book', BookSchema)

I also ran into the same issue as I am doing the same tutorial.我在做同样的教程时也遇到了同样的问题。 What I did to resolve this issue is go to the populatedb.js link they provide in the first step of the "Testing - create some items" or you can download it.我为解决此问题所做的工作是转到他们在“测试 - 创建一些项目”的第一步中提供的 poppedb.js 链接,或者您可以下载它。 Once I clicked on the link, they provide test data that you can paste into the populatedb.js file you've created in the root of your project then:单击链接后,他们会提供测试数据,您可以将这些数据粘贴到您在项目根目录中创建的 poppedb.js 文件中,然后:

  1. npm install async --save
  2. node populatedb <your mongodb url>
  3. Script should run and you should see the results or items as it creates them.脚本应该会运行,您应该会在创建结果或项目时看到它们。

Followed the MDN tutorial, Here is what I fixed:遵循 MDN 教程,这是我修复的内容:

username:Jeff ;用户名:杰夫; password : 12345密码:12345

app.js, change to: app.js,改为:

var mongoDB = 'mongodb://Jeff:123@ds149732.mlab.com:49732/local_library';

Command Line prompt, change to:命令行提示符,更改为:

node populatedb mongodb://Jeff:12345@ds149732.mlab.com:49732/local_library

Posting here because this answer is the result I found googling the problem.在这里发帖是因为这个答案是我在谷歌上搜索问题的结果。

Had the same problem, the error ended up being the password I have set for the admin on the database - special characters were encoded (there was a warning displayed which I apparently ignored) which caused me to not be able to connect.有同样的问题,错误最终是我在数据库上为管理员设置的密码 - 特殊字符被编码(有一个警告显示,我显然忽略了)导致我无法连接。

I had this issue for a couple of days with the error我遇到这个问题几天了

zsh: no matches found: <my mongodb url>

First, I double checked I had followed the instructions in Testing — create some items in the tutorial.首先,我仔细检查了我是否遵循了测试中的说明——在教程中创建了一些项目 Then I changed my original mongodb URL in the terminal, removing the end.然后我在终端中更改了我原来的 mongodb URL,删除了结尾。

My original mongoURL =我原来的 mongoURL =

mongodb+srv://username:password@cluster0.9f24o.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

My new mongoURL =我的新 mongoURL =

mongodb+srv://username:password@cluster0.9f24o.mongodb.net/myFirstDatabase

I ran this script while in my express-locallibrary tutorial folder.我在 express-locallibrary 教程文件夹中运行了这个脚本。

node populatedb mongodb+srv://username:password@cluster0.9f24o.mongodb.net/myFirstDatabase

I'm not sure at this point if this means I need to change the link in app.js as well.我现在不确定这是否意味着我还需要更改 app.js 中的链接。

Hopefully this saves someone some time!希望这可以节省一些时间!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM