This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require("express"); | |
var path = require("path"); | |
var bodyParser = require("body-parser"); | |
var mongodb = require("mongodb"); | |
var ObjectId = require("mongodb").ObjectID; | |
var app = express(); | |
app.use(express.static(__dirname + "/public")); | |
app.use(bodyParser.json()); // for parsing application/json | |
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ****************************** CONTACTS API ROUTES ****************************************** | |
// Generic error handler used by all endpoints. | |
function handleError(code, e, res, message) { | |
res.status(500).json({"error": message, "reason": e.message || "unknown"}); | |
} | |
/* "/contacts" | |
* GET: grabs all contacts | |
* POST: creates a new contact |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* MongoDB NodeJS Driver Production Connection Example | |
* | |
* Copyright (c) 2015 ObjectLabs Corporation | |
* Distributed under the MIT license - http://opensource.org/licenses/MIT | |
*/ | |
var MongoClient = require('mongodb').MongoClient; | |
/** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var debug = require('debug')('gcpNode'); | |
var app = require('../app'); | |
var mongodb = require('mongodb'); | |
app.set('port', process.env.PORT || 3000); | |
mongodb.MongoClient.connect(MONGODB_URI, function(err, db) { | |
// do error handling here | |
if(err) throw err; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Options are documented here: https://cloud.google.com/appengine/docs/managed-vms/config. | |
module: default | |
version: 1 | |
runtime: custom | |
vm: true | |
api_version: 1 | |
manual_scaling: | |
instances: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymongo | |
client = pymongo.MongoClient("MONGODB_ADMINDB_URI") #admin database URI | |
# Create a new database "dynamic" | |
db = client.dynamic | |
# Save doc to collection "test" | |
db.test.save({"foo":"bar"}) | |
# Create a new database "dynamic2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var mongodb = require('mongodb'); | |
var app = express(); | |
var MONGODB_URI = 'mongodb-uri'; | |
var db; //gives you a global db variable you can pass around | |
mongodb.MongoClient.connect(MONGODB_URI, function(err, database) { | |
if(err) throw err; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MongoClient = require('mongodb').MongoClient, | |
Server = require('mongodb').Server, | |
Db = require('mongodb').Db, | |
ReplSetServers = require('mongodb').ReplSetServers; | |
var url = 'MONGODB_URI'; | |
// You can connect to any database here. Likely whichever connection you want to be persistent | |
MongoClient.connect(url, function(err, uriDb) { | |
if(err) console.log(err); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
catch (MongoConnectionException e) | |
{ | |
Console.WriteLine(e.ToString()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using MongoDB.Bson; | |
using MongoDB.Driver; | |
using MongoDB.Driver.Builders; | |
namespace Tester | |
{ | |
class Test | |
{ |