mongoskin

Configuring Node.js Connection String for Mongo Labs Database on Heroku

只愿长相守 提交于 2019-12-01 11:17:08
问题 My web app (built on Node.js and Express) works fine locally, but when I deploy it to Heroku, I'm unable to connect to my Mongo Labs database. I've changed the connection string in my 'app.js' file to properly reflect the URI of the new Heroku Mongo Labs database (fake username and password substituted below). I've also tried several stackoverlow solutions can't connect to mongolab with node.js on heroku as well as https://devcenter.heroku.com/articles/getting-started-with-nodejs#using

How to get a instance of db from node-mongo native driver?

本小妞迷上赌 提交于 2019-12-01 08:08:07
Consider, I have MongoDB connection opened in the main app.js file itself and the following code fall in it's call back: mongodb.connect('MongoDBUrlGoesHere', function (err, db) { app.listen(app.get('port'), function AppListnCB() { console.log("Server listening on port " + app.get('port')); }); }); This is all done to have only one db instance across the application. Now, If we are in another external.js file and need a same db object which is aleady has connected. This can be done very easily if we are using mongoskin or mongoose Can someone help me to find how this can be done with native

MongoDb unique constraints on a Date range

≡放荡痞女 提交于 2019-12-01 05:43:36
问题 Im using MongoDb with Mongoskin. In a collection I'm saving events. Among other fields, these events have a start and an end, saved as Dates in Mongodb. events { start: "Date1", end: "Date2", ... } When inserting new documents in this collection I need a constrain that forbids insertion of document which start-end dates overlapping an event alreay created. In short, I dont want any events share the same time span. Question: Is there a way to handle this constraint trough MongoDb with some

Iterating over a mongodb cursor serially (waiting for callbacks before moving to next document)

心不动则不痛 提交于 2019-11-29 20:26:00
Using mongoskin, I can do a query like this, which will return a cursor: myCollection.find({}, function(err, resultCursor) { resultCursor.each(function(err, result) { } } However, I'd like to call some async functions for each document, and only move on to the next item on the cursor after this has called back (similar to the eachSeries structure in the async.js module). E.g: myCollection.find({}, function(err, resultCursor) { resultCursor.each(function(err, result) { externalAsyncFunction(result, function(err) { //externalAsyncFunction completed - now want to move to next doc }); } } How

How to use unordered bulk inserting with Mongoskin?

人盡茶涼 提交于 2019-11-29 12:37:28
I'm having trouble using Mongoskin to perform bulk inserting (MongoDB 2.6+) on Node. var dbURI = urigoeshere; var db = mongo.db(dbURI, {safe:true}); var bulk = db.collection('collection').initializeUnorderedBulkOp(); for (var i = 0; i < 200000; i++) { bulk.insert({number: i}, function() { console.log('bulk inserting: ', i); }); } bulk.execute(function(err, result) { res.json('send response statement'); }); The above code gives the following warnings/errors: (node) warning: possible EventEmitter memory leak detected. 51 listeners added. Use emitter.setMaxListeners() to increase limit. TypeError

Iterating over a mongodb cursor serially (waiting for callbacks before moving to next document)

こ雲淡風輕ζ 提交于 2019-11-28 15:56:56
问题 Using mongoskin, I can do a query like this, which will return a cursor: myCollection.find({}, function(err, resultCursor) { resultCursor.each(function(err, result) { } } However, I'd like to call some async functions for each document, and only move on to the next item on the cursor after this has called back (similar to the eachSeries structure in the async.js module). E.g: myCollection.find({}, function(err, resultCursor) { resultCursor.each(function(err, result) { externalAsyncFunction

How to use unordered bulk inserting with Mongoskin?

筅森魡賤 提交于 2019-11-28 06:27:10
问题 I'm having trouble using Mongoskin to perform bulk inserting (MongoDB 2.6+) on Node. var dbURI = urigoeshere; var db = mongo.db(dbURI, {safe:true}); var bulk = db.collection('collection').initializeUnorderedBulkOp(); for (var i = 0; i < 200000; i++) { bulk.insert({number: i}, function() { console.log('bulk inserting: ', i); }); } bulk.execute(function(err, result) { res.json('send response statement'); }); The above code gives the following warnings/errors: (node) warning: possible

Nodejs Mongo insert into subdocument - dynamic fieldname

流过昼夜 提交于 2019-11-26 18:31:50
问题 {username:'me', companies:{"yourcompany":{...}} I want to insert a company into a user record (user collection), to make: {username:'me', companies:{ "yourcompany":{...}, "mycompany":{...} } But the name is dynamic.. var companyid = "mycompany"; .collection('users').findAndModify( {username: usern}, [['_id', 'asc']], {$set:{companies:{companyid: { desksmemberships:[] }}}}, {new: true}, function(){...} Gives this.. {username:'me', companies:{ "yourcompany":{...}, "companyid":{...} } How do I