Created
October 25, 2018 09:04
-
-
Save snmmaurya/ab05b18f9126e13414337bd742346555 to your computer and use it in GitHub Desktop.
node mongodb implementation
This file contains 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
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