In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Http://cnodejs.org/topic/57baa91ddcaeb5d932db223b
# connection code var conn = mongoose.connect ('mongodb://username:password@127.0.0.1:27017/test?authMechanism=MONGODB-CR')
# error > MongoError: server 127.0.0.1 timed out 27017
# try to connect with the command line > mongo-u username-p password 127.0.0.1 MongoDB shell version: 2.4.9 connecting to: 127.0.0.1:27017/test Error while trying to show server startup warnings: not authorized on admin to execute command {getLog: "startupWarnings"}
The connection is successful and there is no problem with performing read and write operations. Could it be a problem with mongoose? # then test it with the mongoDB driver.
Var MongoClient = require ('mongodb'). MongoClient; var url =' mongodb://username:password@127.0.0.1:27017/test?authMechanism=MONGODB-CR'; MongoClient.connect (url, function (err, db) {console.log (err? Err: 'mongoDB connection succeeded!');})
> node mongoDB.js mongoDB connection succeeded!
Since mongoose is based on mongoDB drivers, this is unlikely to happen. Could it be that mongoose does not recognize the url parameter. Next, remove the string MongoError: server 127.0.0.1 timed out 27017 timed out from'? authMechanism=MONGODB-CR'. Sure enough, mongoose could not recognize this parameter, and then looked through the document [mongoose document] http://mongoosejs.com/docs/api.html Ctrl+F paste authMechanism and couldn't find it. Click connection.js directly to find this line of auth-options for authentication (see http://mongodb.github.com/node-mongodb-native/api-generated/db.html#authenticate) clicks in to find what we want.
Modify the code to configure options as Object!
Const options = {user: "username", pass: "password", auth: {authMechanism: 'MONGODB-CR'}} var conn = mongoose.connect (' mongodb://@127.0.0.1:27017/test',options)
Rerun node app.js [2016-08-22 15 console 21 app listen to 39.709] [INFO] console-app listen to 3000, NODE_ENV: development perfect! Well, it's healthier to step on, especially for us newcomers.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.