Skip to content

Instantly share code, notes, and snippets.

@snmmaurya
Created October 25, 2018 09:04
Show Gist options
  • Save snmmaurya/ab05b18f9126e13414337bd742346555 to your computer and use it in GitHub Desktop.
Save snmmaurya/ab05b18f9126e13414337bd742346555 to your computer and use it in GitHub Desktop.
node mongodb implementation
References: https://mongoosejs.com/
Steps to start with mongoose-
install mongoose
npm install mongoose
create file config/dynamodb.rb
var mongoose = require('mongoose');
mongoose.AWS.config.update({
accessKeyId: aws_dynamodb_access_key,
secretAccessKey: aws_dynamodb_secret_key,
region: process.env.aws_dynamodb_region,
});
module.exports = mongoose;
Create file dynamodb/user.rb
// include configuration file
const mongoose = require('../config/dynamodb')
// Create User model
var User = mongoose.model('users',
{
name: String,
email: String,
status: Boolean,
user_id: Boolean
});
// Custom methods
User.customMethod = function(parameters){
};
module.exports = DynamoBinanceTrade;
Queries-
How to insert -
var user = new User({email: 'email', name: 'name', user_id: 'user_id', status: 'status'});
user.save(function (error){
if(!error){
console.log("saved");
}else{
console.log("Error: "+ error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment