Skip to content

Instantly share code, notes, and snippets.

@am-MongoDB
am-MongoDB / index.js
Created March 13, 2017 08:58
Amazon Alexa skill to access MongoDB
"use strict";
var Alexa = require("alexa-sdk");
var request = require("request");
var config = require("./config.js");
exports.handler = function(event, context, callback) {
console.log("In handler");
@am-MongoDB
am-MongoDB / react-native.js
Created March 13, 2017 08:57
React Native components
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class HelloWorldApp extends Component {
render() {
return (
<View>
<Text>Hello There!</Text>
<Text>This is a very simple Native React component.</Text>
</View>
var config = {
expressPort: 3000,
client: {
mongodb: {
defaultDatabase: "mongopop",
defaultCollection: "simples",
defaultUri: "mongodb://localhost:27017"
},
mockarooUrl: "http://www.mockaroo.com/536ecbc0/download?count=1000&key=48da1ee0"
},
@am-MongoDB
am-MongoDB / db.js
Created March 13, 2017 08:55
Access MongoDB from Express route
DB.prototype.mostRecentDocument = function(coll) {
// Return a promise that either resolves with the most recent docucment
// from the collection (based on a reverse sort on `_id` or is rejected with the error
// received from the database.
var _this=this;
return new Promise(function (resolve, reject) {
_this.db.collection(coll, {strict:false}, function(error, collection){
@am-MongoDB
am-MongoDB / pop.js
Created March 13, 2017 08:54
Mongopop Express route implementation
router.post('/checkIn', function(req, res, next) {
/* Request from client to add a sample of the documents from a collection; the request
should be of the form:
{
venue,
date,
url,
location
import React from 'react';
export class ServerDetails extends React.Component {
constructor(props) {
super(props);
this.state = {serverIP: ""};
this.componentDidMount = this.componentDidMount.bind(this);
}
import React from 'react';
import './App.css';
export class ConnectionInfo extends React.Component {
constructor(props) {
super(props);
this.state = {
MongoDBBaseURI: "",
MongoDBDatabaseName: "",
@am-MongoDB
am-MongoDB / App.js
Last active February 21, 2017 13:27
import React, { Component } from 'react';
import './App.css';
import { DataService } from './data.service';
import { ServerDetails } from './server.details.component';
import { ConnectionInfo } from './connection.info.component';
import { CollectionName } from './collection.name.component';
import { CountDocuments } from './count.component';
import { AddDocuments } from './add.component';
import { UpdateDocuments } from './update.component';
import { SampleDocuments } from './sample.component';
if (this.state.repeat) {
this.timerID = setInterval(
() => this.countOnce(),
5000
);
}
import React from 'react';
import './App.css';
export class UpdateDocuments extends React.Component {
constructor(props) {
super(props);
this.state = {
matchPattern: '{"field-name": "value"}',
changePattern: '{"$set":{"mongopopComment": "MongoPop has been here"}, "$inc":{"mongopopCounter": 1}}',