[Error: failed to connect to [localhost:27017]] from NodeJS to mongodb

后端 未结 6 903
不知归路
不知归路 2021-01-01 18:11

I am having problem connecting to MongoDB from NodeJS using following sample code. I tried running \"mongod\" with or without sudo but nodejs code still fail to connect. I a

6条回答
  •  Happy的楠姐
    2021-01-01 18:36

    The first time, I made the obvious mistake that mongod (the mongo Server) was not even running.

    The second time, I had both the Server (mongod) and the Client (mongo) running on my Windows; in separate Command Prompts (of course mongo running first). mongod and/or its Command Prompt was "hung up" (i.e. the last line only said this, and the last line remained like this despite attempts to connections:)

    2017-06-20T12:31:02.937-0600 I NETWORK  [thread1] waiting for connections on port 27017
    

    I clicked in the Command Prompt pressed the space-bar to "kick it" , and the Command Prompt printed lines like these:

    2017-06-20T12:31:48.517-0600 I NETWORK  [thread1] connection accepted from 127.0.0.1:50260 #1 (1 connection now open)
    

    Which worked!

提交回复
热议问题