Skip to content

Instantly share code, notes, and snippets.

@gonzalovazquez
Last active December 10, 2016 09:40
Show Gist options
  • Save gonzalovazquez/7413658 to your computer and use it in GitHub Desktop.
Save gonzalovazquez/7413658 to your computer and use it in GitHub Desktop.
NodeJS connection to MongoDB
var databaseUrl = "mongolaburl"; // "username:[email protected]/mydb"
var collections = ["Persons"];
var db = require("mongojs").connect(databaseUrl, collections);
//Find a Person
db.Persons.find({sex: "male"}, function(err, users) {
if( err || !users) console.log("No male users found");
else users.forEach( function(maleUser) {
console.log(maleUser);
} );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment