Question: I am connecting to Gmail account using TCP client for reading emails. It returns SslStream for the TCP connection. It works fine for single thread environment but performance is very poor in terms of speed. 

I need to optimize the project so that its speed can be increased. I have implemented multithreading which increases the speeed but application gets hang at some point. 

Is it thread safe to use TCP connection (global member)?

OR Can I create multiple TCP connections and pass to the thread method to increase the speed ?

OR is there any other better way for doing this?

```
TCPClient m_TCPclient
SslStream sslStream;

private void createTCP()
{
// creating tcp and sslstream
}

private void authenticateUser()
{
// authenticating the user
}

private void getUserdata()
{

// iterating folders and its items
foreach(string emailID in IDList)
{
//Thread implementation

}

```

Answer: 
If you wish to execute just a single command, you could do it with:

```
mongo server:22021/my_dbname --eval "printjson(db.serverStatus())"

```

If you wish to execute multiple commands say residing in a file called command.js, you could do something like:

```
mongo server:22021/my_dbname --quiet commands.js

```

If you want pure shell script (SQL) style, then you could do something like:

```
function testMongoScript {
    mongo server:22021/my_dbname <<EOF
       use mydb
       db.leads.findOne()
       db.leads.find().count()
    EOF
}

```

For further details, you could refer [here](http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/) as well.
You can use output redirection to run whatever command you need:

```
mongo localhost:27017 <<< $'rs.slaveOk()\nshow dbs'

```

or 

```
echo $'rs.slaveOk()\nshow dbs' | mongo localhost:27017

```

just remember the `\n` between commands.