CopyPastor

Detecting plagiarism made easy.

Score: 0.7510316371917725; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-07-12
by ORBIT

Original Post

Original - Posted on 2019-04-02
by Naresh\_Varma



            
Present in both answers; Present only in the new answer; Present only in the old answer;

According to [connPoolStats][1]
this command .`connPoolStats`. returns information regarding the open outgoing connections from the current database instance to other members of the sharded cluster or replica set.
db.runCommand( { "connPoolStats" : 1 } )
The value of the argument (i.e. 1 ) does not affect the output of your the command.
According to [connection pool options][2]
The maximum number of connections in the connection pool. **The default value is 100**.
According to this it can be done [deep-dive-into-connection-pooling][3]
var express = require('express'); var mongodb = require('mongodb'); var app = express(); var MONGODB_URI = 'mongo-uri'; app.get('/', function(req, res) { // BAD! Creates a new connection pool for every request mongodb.MongoClient.connect(MONGODB_URI, function(err, db) { if(err) throw err; var coll = db.collection('test'); coll.find({}, function(err, docs) { docs.each(function(err, doc) { if(doc) { res.write(JSON.stringify(doc) + "\n"); } else { res.end(); } }); }); }); }); // App may initialize before DB connection is ready app.listen(3000); console.log('Listening on port 3000');

[1]: https://docs.mongodb.com/manual/reference/command/connPoolStats/ [2]: https://docs.mongodb.com/manual/reference/connection-string/#connection-pool-options [3]: https://blog.mlab.com/2013/11/deep-dive-into-connection-pooling/
If you opt for using mongoose in your application edit your app.js file with the following snippet
**app.js**
const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/Your_Data_Base_Name', {useNewUrlParser:true}) .then((res) => { console.log(' ########### Connected to mongDB ###########'); }) .catch((err) => { console.log('Error in connecting to mongoDb' + err); });`
**Next Step:** Define Models for your application require them and perform CRUD operation directly for example
**blogSchema.js**
const mongoose = require('mongoose'); const Schema = mongoose.Schema; const blogSchema = new Schema({ _id : mongoose.Schema.Types.ObjectId, title : { type : 'String', unique : true, required : true }, description : String, comments : [{type : mongoose.Schema.Types.ObjectId, ref: 'Comment'}] }); module.exports = mongoose.model('Blog', blogSchema); **Usage** **createBlog.js**
const Blog = require('../models/blogSchema'); exports.createBlog = (req, res, next) => { const blog = new Blog({ _id : new mongoose.Types.ObjectId, title : req.body.title, description : req.body.description, }); blog.save((err, blog) => { if(err){ console.log('Server Error save fun failed'); res.status(500).json({ msg : "Error occured on server side", err : err }) }else{ //do something.... } U don't need to connect to mogoDB always ....


        
Present in both answers; Present only in the new answer; Present only in the old answer;