How to use mongojs - 10 common examples

To help you get started, we’ve selected a few mongojs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GLAMpipe / GLAMpipe / app / project.js View on Github external
if(global.config.authentication === "local") {
		if(req.user && req.user.local && req.user.local.email && req.user.local.email) {
			var id = req.params.project;
			//  we are authenticating for project operation (add/remove node)
			if(id) {
				mongoquery.findOneById(id, "mp_projects", function(project) {
					if(project.owner.includes(req.user.local.email))
						cb(true);
					else
						cb(false);
				});
			// we are authenticating for node run (separate since there is no project id on node run URL)
			} else {
				var nodeid = mongojs.ObjectId(req.params.id);
				mongoquery.findOne({nodes:{$elemMatch:{_id:nodeid}}}, "mp_projects", function(err, project) {
					if(!err) {
						if(project && project.owner.includes(req.user.local.email) )
							cb(true);
						else
							cb(false);
					} else {
						cb(false);
					}
				})
			}
		} else {
			cb(false); // we do not have user
		}
	} else if (global.config.authentication === "shibboleth") {
		console.log(req.headers[global.config.shibbolethHeaderId])
github GLAMpipe / GLAMpipe / app / project.js View on Github external
// first check if route should be open
	var pass = false;
	global.config.IP_passes.some(function(IP_pass) {
		if(req.path.includes(IP_pass.path) && req.method === IP_pass.method && (req.ip === IP_pass.ip || IP_pass.ip === "*")) {
			pass = true;
			console.log("INFO: " + req.method + " allowed by IP_pass: " + IP_pass.label)
		}
	})
	if(pass)
		return next();

	var user = getUser(req)
	var node_uuid = req.params.id;
	
	try {
		node_uuid = mongojs.ObjectId(req.params.id);
	} catch(e) {
		res.status(404).json({error:"Node not found!"});
	}

	mongoquery.findOne({nodes:{$elemMatch:{_id:node_uuid}}}, "mp_projects", function(err, project) {
		if(!err) {
			if(project && user && project.owner.includes(user) )
				next()
			else
				res.status(401).json({error:"Node run not authenticated!"});
		} else {
			res.status(401).json({error:"Node run not authenticated!"});
		}
	})
}
github maxvyaznikov / imapseagull / app_tests.js View on Github external
function prepareMessage(message) {
    message.user = mongojs.ObjectId(''+ app_tests.testuser._id);
    message.folder = message.folder || '\\Inbox';
    message.flags = message.flags || [];

    message.uid = message.uid || app_tests.uidnext;
    app_tests.uidnext = message.uid + 1;

    message.internaldate = message.internaldate || new Date();
    return message;
}
github michaelcheng924 / meanstacktutorial / server.js View on Github external
app.delete('/contactlist/:id', function (req, res) {
  var id = req.params.id;
  console.log(id);
  db.contactlist.remove({_id: mongojs.ObjectId(id)}, function (err, doc) {
    res.json(doc);
  });
});
github artsy / positron / src / api / apps / articles / model / index.js View on Github external
export const find = (id, callback) => {
  const query = ObjectId.isValid(id) ? { _id: ObjectId(id) } : { slugs: id }
  db.articles.findOne(query, callback)
}
github GLAMpipe / GLAMpipe / app / controllers / user.js View on Github external
static findById(id, cb) {
		mongoquery.findOne({"_id":mongojs.ObjectId(id)}, "mp_users", function (err, result) {
			if (err) {
				cb(err)
			} else if(result) {
				var user = new User(result.local.email);
				user.id = result._id; 
				cb(null, user);
			} else {
				cb(null, null);
			}
		}); 
	}
github arxitics / arxiv-analytics / models / account.js View on Github external
exports.access = function (uid, oid, callback) {
  var criteria = {'uid': uid};
  if (typeof oid === 'function') {
    callback = oid;
  } else if (oid) {
    criteria['_id'] = require('mongojs').ObjectId(oid);
  }
  callback = (typeof callback === 'function') ? callback : function () {};
  exports.update(criteria, {
    '$set': {
      'auth.seen': new Date(),
      'auth.status': 'online'
    }
  }, function (user) {
    if (user) {
      callback(user);
    } else {
      exports.guest(callback);
    }
  });
};
github masylum / whatajong / app.js View on Github external
http.get('/game/:room_id', authorize, function (req, res, next) {
  var query = {_id: require('mongojs').ObjectId(req.param('room_id'))}
    , js = ['vendor/uuid', 'tile', 'client', 'mouse', 'confirm'];

  db.rooms.findOne(query, function (error, room) {
    if (error) return next(error);

    var options = { room: room
                  , user: req.user
                  , css: asereje.css()
                  , js: asereje.js(js)
                  };

    if (room) {
      res.render('room', options);
    } else {
      res.render('inexistant_room', options);
    }
github javascript-playground / express-backbone-library-app / database.js View on Github external
var dbUrl = "library";
var collections = ["books"];

var db = require("mongojs").connect(dbUrl, collections);
module.exports = db;
github likeastore / app / source / utils / dbConnector.js View on Github external
var setDb = function (options) {
	var url = options.url ? options.url : config.connection,
		list = options.collections ? options.collections : collections;

	return mongo.connect(url, list);
};

mongojs

Easy to use module that implements the mongo api

MIT
Latest version published 5 years ago

Package Health Score

51 / 100
Full package analysis

Popular mongojs functions