Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MongoClient = require('mongodb').MongoClient
- var url = 'mongodb://localhost:27017/myproject';
- function output (user, orders) {
- // output data in pretty format
- }
- function logError (error) {
- // Log the error (could be console, a service, a file etc)
- }
- // Connect to mongo server
- MongoClient.connect(url, (err, db) => {
- const userId = process.argv[2];
- db.collection('access_log').insert({ userId, date: new Date() }, (err, result) => {
- if (err) {
- logError(err);
- } else {
- db.collection('users').find({ userId }).toArray((err, users) => {
- if (err) {
- logError(err);
- } else {
- db.collection('orders').find({ userId }).toArray((err, orders) => {
- if (err) {
- logError(err);
- } else {
- output(users[0], orders);
- }
- });
- }
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement