monk

not able to connect to mongodb hosted on remote server using monk

倾然丶 夕夏残阳落幕 提交于 2020-01-02 12:23:22
问题 I am using node js, and for the backend i am using mongodb For connecting to DB, if i use the below line, it is fetching data var db = monk('localhost:27017/nodetest2'); But if i change that to below line, its not fetching the data var db = monk('mongodb://username:password@XXX.mongolab.com:27483/userdb'); I have created the collection with same name in both places router.get('/userlist', function (req, res) { var db = req.db; var collection = db.get('userlist'); collection.find({}, {},

Argument passed in must be a string of 24 hex characters - I think it is

微笑、不失礼 提交于 2020-01-02 02:53:15
问题 I have a method to find a document in my database based on its ObjectID: console.log('id: ' + id + ' type: ' + typeof id); collection.findOne({'_id':new ObjectID(id)}, function(error,doc) { if (error) { callback(error); } else { callback(null, doc); } }); When I run it I get the following error: /myPath/node_modules/monk/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/base.js:245 throw message; ^ Error: Argument passed in must be a single String of 12 bytes or a string of

Chaining nested asynchronous finds with Node.js monk and MongoDB

和自甴很熟 提交于 2019-12-25 16:08:45
问题 Using Node.js monk and MongoDB, I want to mimic a table join: Do a find on collection A For each result X, do a find in collection B, and update X Return updated list of results The asynchronous nature of database commands in monk is giving me trouble. This is my initial code. It doesn't work because the second call to find returns a promise immediately, and the results in xs are sent in the response before they can be updated. var db = require('monk')('localhost/mydb'); db.get('collection')

unit testing express route with async callback

被刻印的时光 ゝ 提交于 2019-12-23 20:17:03
问题 I'm writing an app in node.js using express. I seperated the route definition from express so I will be able to unit test it without mocking out express. What I did is: file: usersRoutes.js var routes = { getAll: function(req,res) { var db = req.db; // req.db is initialized through a dedicated middleware function var usersCollection = db.get('users'); usersCollection.find({},{limit:10},function(e,results){ res.send(results); }); } }; module.exports = routes; file: users.js var express =

Issue with a simple mongo/monk findAndModify query

拜拜、爱过 提交于 2019-12-13 18:41:12
问题 Just a note I am fairly new to mongo and more notably very new to using node/js. I'm trying to write a query to insert new documents or update already existing documents in my collection. The proposed structure of the collection is: { _id: xxxxxxx, ip: "xxx.xxx.xxx.xxx:xxxxxx", date: "xx-xx-xx xxxx" } Note that my intention is a store an fixed length int for the _id rather than the internal ObjectId (is this possible/considered bad practice?). The int is guaranteed to be unique and comes from

not able to connect to mongodb hosted on remote server using monk

蓝咒 提交于 2019-12-06 05:15:40
I am using node js, and for the backend i am using mongodb For connecting to DB, if i use the below line, it is fetching data var db = monk('localhost:27017/nodetest2'); But if i change that to below line, its not fetching the data var db = monk('mongodb://username:password@XXX.mongolab.com:27483/userdb'); I have created the collection with same name in both places router.get('/userlist', function (req, res) { var db = req.db; var collection = db.get('userlist'); collection.find({}, {}, function (e, docs) { res.json(docs); }); }); 来源: https://stackoverflow.com/questions/31668288/not-able-to

Argument passed in must be a string of 24 hex characters - I think it is

百般思念 提交于 2019-12-05 04:43:49
I have a method to find a document in my database based on its ObjectID: console.log('id: ' + id + ' type: ' + typeof id); collection.findOne({'_id':new ObjectID(id)}, function(error,doc) { if (error) { callback(error); } else { callback(null, doc); } }); When I run it I get the following error: /myPath/node_modules/monk/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/base.js:245 throw message; ^ Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters at new ObjectID (/myPath/node_modules/mongodb/node_modules/bson/lib/bson/objectid.js

Mongo db with Monk: error catching and handling if db is down

烂漫一生 提交于 2019-12-04 04:38:37
问题 I'm new to Mongo. I needed a database for a simple project and ended up following a tutorial using Mongo with Monk but I have problems understanding how to handle errors. Background : I have a registration form on the client side. When the user clicks a button, the data is sent via AJAX to the controller that (upon validation, but this is not relevant now) inserts such data into the database and sends back either success or error. When the db is up all seems to work fine. The problem : If I

monk vs mongoose for Mongodb

佐手、 提交于 2019-12-03 03:25:32
问题 I'm learning NodeJs. To connect to and use MongoDB from NodeJS, I see a lot of examples using either Monk or Mongoose. Are these two libraries equivalent ? Do they have the same features or do they each have a specific purpose ? As a beginner with NodeJS, which should I use ? Here are some examples of code that uses Monk : var mongo = require('mongodb'); var monk = require('monk'); var db = monk('localhost:27017/nodejsapp'); ---- exports.userlist = function(db) { return function(req, res) {

monk vs mongoose for Mongodb

爱⌒轻易说出口 提交于 2019-12-02 16:55:44
I'm learning NodeJs. To connect to and use MongoDB from NodeJS, I see a lot of examples using either Monk or Mongoose. Are these two libraries equivalent ? Do they have the same features or do they each have a specific purpose ? As a beginner with NodeJS, which should I use ? Here are some examples of code that uses Monk : var mongo = require('mongodb'); var monk = require('monk'); var db = monk('localhost:27017/nodejsapp'); ---- exports.userlist = function(db) { return function(req, res) { var collection = db.get('users'); collection.find({},{},function(e,docs){ res.render('userlist', {