ExtraDRM : Design Ressource Management

Web content and data design solutions

Browsing Posts published by extradrm

Shell Mongo :
> mongo

Once you are in terminal/command line, access the database/collection you want to use as follows:

show dbs
use <db name>
show collections

choose your collection and type the following to see all contents of that collection:


for a query below some samples :

db.products.find({ "_id": "apples", "qty": 5 }
db.products.find( { qty: { $gt: 25 } } )
db.students.find( { score: { $gt: 0, $lt: 2 } } )
db.bios.find( { _id: 5 } )
db.bios.find( { contribs: "UNIX" } ) >>>>>> Array elements

Check this link for more : https://docs.mongodb.com/manual/reference/method/db.collection.find/

Import / Export command in MongoDB (Unicode files)(json)

mongoimport -d comedy -c cartoons -file collections.json
mongoexport -d comedy -c cartoons -o collections.json

Change collection name in mongodb


Change type fields :

// String to Integer for notice_id
db.mycollection.find({notice_id : {$exists : true}}).forEach( function(obj) { obj.notice_id = new NumberInt(obj.notice_id); db.mycollection.save(obj); } );
// Integer to String for field-name
db.db-name.find({field-name : {$exists : true}}).forEach( function(obj) { obj.field-name = ""+obj.field-name; db.db-name.save(obj); } );

Rename a field in mongoDB :

db.mycollection.update ( {}, { $rename : { "notice_id" : "isn" }}, false, true );

Delete a collection


Empty a collection


Under the Mongodb shell please import the follwing json file (test.json) listed below with :

mongoimport -d test -c compta -file d:test.json

{ “montant” : 3.95, “travel” : “Prague”, “sens” : “credit” }
{ “montant” : 6.03, “travel” : “Prague”, “sens” : “credit” }
{ “montant” : 5.53, “travel” : “New York”, “sens” : “credit” }
{ “montant” : -1.96, “travel” : “New York”, “sens” : “debit” }
{ “montant” : 3.95, “tickets” : “eurodisney”, “sens” : “credit” }
{ “montant” : 6.03, “tickets” : “asterix”, “sens” : “credit” }

Mongo Request Sum or Total aggregate :

montant: {$sum: "$montant"}}
}, {$project:{
montant: "$montant"}});

montant: {$sum: "$montant"}}
}, {$project:{
montant: "$montant"}});


The two mainstream protocols available for Secure FTP transfers are named SFTP (FTP over SSH) and FTPS (FTP over SSL). Both SFTP and FTPS offer a high level of protection since they implement strong algorithms such as AES and Triple DES to encrypt any data transferred. Both options also support a wide variety of functionality with a broad command set for transferring and working with files. So the most notable differences between SFTP and FTPS is how connections are authenticated and managed.

With SFTP (FTP over SSH)

A connection can be authenticated using a couple different techniques.  For basic authentication, you (or your trading partner) may just require a user id and password to connect to the SFTP server. Its important to note that any user ids and passwords supplied over the SFTP connection will be encrypted, which is a big advantage over standard FTP.

SSH keys can also be used to authenticate SFTP connections in addition to, or instead of, passwords. With key-based authentication, you will first need to generate a SSH private key and public key beforehand. If you need to connect to a trading partner’s SFTP server, you would send your SSH public key to them, which they will load onto their server and associate with your account. When you connect to their SFTP server, your client software will transmit your public key to the server for authentication. If the keys match, along with any user/password supplied, then the authentication will succeed.

With FTPS (FTP over SSL)

A connection is authenticated using a user id, password and certificate(s).  Like SFTP, the users and passwords for FTPS connections will also be encrypted. When connecting to a trading partner’s FTPS server, your FTPS client will first check if the server’s certificate is trusted. The certificate is considered trusted if either the certificate was signed off by a known certificate authority (CA), like Verisign, or if the certificate was self-signed (by your partner) and you have a copy of their public certificate in your trusted key store.

Your partner may also require that you supply a certificate when you connect to them.  Your certificate may be signed off by a 3rd party CA or your partner may allow you to just self-sign your certificate, as long as you send them the public portion of your certificate beforehand (which they will load in their trusted key store).

In regards to how easy each of the secure FTP protocols are to implement, SFTP is the clear winner since it is very firewall friendly. SFTP only needs a single port number (default of 22) to be opened through the firewall.  This port will be used for all SFTP communications, including the initial authentication, any commands issued, as well as any data transferred.

On the other hand, FTPS can be very difficult to patch through a tightly secured firewall since FTPS uses multiple port numbers. The initial port number (default of 21) is used for authentication and passing any commands.  However, every time a file transfer request (get, put) or directory listing request is made, another port number needs to be opened.  You and your trading partners will therefore have to open a range of ports in your firewalls to allow for FTPS connections, which can be a security risk for your network.

In summary, SFTP and FTPS are both very secure with strong authentication options.  However since SFTP is much easier to port through firewalls, and we are seeing an increasing percentage of trading partners adopting SFTP, I believe SFTP is the clear winner for your secure FTP needs.

Related Articles :











FTP is a very insecure protocol because all passwords and all data are transferred in clear text. By using TLS, the whole communication can be encrypted, thus making FTP much more secure. This article explains how to configure PureFTPd to accept TLS sessions on a Debian Lenny server.

1 Installing OpenSSL

OpenSSL is needed by TLS; to install OpenSSL, we simply run (verify version or if installed / openssl version) :

aptitude install openssl

2 Configuring PureFTPd

If you want to allow FTP and TLS sessions, run

echo 1 > /etc/pure-ftpd/conf/TLS

If you want to accept TLS sessions only (no FTP), run

echo 2 > /etc/pure-ftpd/conf/TLS


To not allow TLS at all (only FTP), either delete /etc/pure-ftpd/conf/TLS or run

echo 0 > /etc/pure-ftpd/conf/TLS


3 Creating The SSL Certificate For TLS

In order to use TLS, we must create an SSL certificate. I create it in /etc/ssl/private/, therefore I create that directory first:

 mkdir -p /etc/ssl/private/

Afterwards, we can generate the SSL certificate as follows:

openssl req -x509 -nodes -days 7300 -newkey rsa:2048 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem

Country Name (2 letter code) [AU]: <– Enter your Country Name (e.g., “DE”).
State or Province Name (full name) [Some-State]:<– Enter your State or Province Name.
Locality Name (eg, city) []:<– Enter your City.
Organization Name (eg, company) [Internet Widgits Pty Ltd]:<– Enter your Organization Name (e.g., the name of your company).
Organizational Unit Name (eg, section) []:<– Enter your Organizational Unit Name (e.g. “IT Department”).
Common Name (eg, YOUR name) []:<– Enter the Fully Qualified Domain Name of the system (e.g. “server1.example.com”).
Email Address []:<– Enter your Email Address.

Change the permissions of the SSL certificate:

chmod 600 /etc/ssl/private/pure-ftpd.pem

Finally restart PureFTPd:

/etc/init.d/pure-ftpd-mysql restart

That’s it. You can now try to connect using your FTP client; however, you should configure your FTP client to use TLS/SSL explicit encryption.