Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Milad Ranjbar miladr0

:octocat:
View GitHub Profile
View .env
PORT=3000
MONGO_USER=mongoadmin
MONGO_PASS=mongoadmin
MONGO_URI=mongodb://127.0.0.1:27017/bull_mongo
#Redis config
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
View hitApi.redisJob.js
import Queue from 'bull';
import models from '../mongoose';
import opts from '../lib/redisConnection';
const hitApiQueue = new Queue('last-login', opts);
hitApiQueue.process(async (job) => {
try {
const { apiUrl } = job.data;
View redicConnection.js
import Redis from 'ioredis';
const PORT = process.env.REDIS_PORT;
const HOST = process.env.REDIS_HOST;
const client = new Redis(PORT, HOST);
const subscriber = new Redis(PORT, HOST);
const opts = {
createClient(type) {
switch (type) {
View mongoose.js
import mongoose from 'mongoose';
import HitApi from './models/hitApi.model';
mongoose.Promise = Promise;
// Exit application on error
mongoose.connection.on('error', (err) => {
console.error(`MongoDB connection error: ${err}`);
process.exit(-1);
});
View hitApi.model.js
import mongoose from 'mongoose';
/**
* HitApi Schema
* @private
*/
const hitApiSchema = new mongoose.Schema({
api: {
type: String,
},
View server.js
import express from 'express';
const app = express();
// respond with "hello world" when a GET request is made to the homepage
app.get('/', (req, res) => {
res.send('hello world');
});
app.get('/api-1', (req, res) => {
View docker-compose.yml
version: "2"
services:
mongodb:
image: mongo
volumes:
- ./volumes/mongodata:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=mongoadmin
- MONGO_INITDB_ROOT_PASSWORD=mongoadmin
ports:
@miladr0
miladr0 / gist:6807d4dbd0141c4f61ddb26b5f464bb1
Created Jan 30, 2019
Restore a Mongodb Database when using authentication
View gist:6807d4dbd0141c4f61ddb26b5f464bb1
sudo mongorestore --username "YourUserName" --password "YourPassword" --authenticationDatabase "admin" --db yourdbname --drop /path/to/archive/folder/