Mongoose Guide-Connection

Source: Internet
Author: User

Create a connection using the Mongoose.connect () method

Mongoose.conect (' Mongodb://localhost/myapp ');

The above code is linked to the MyApp database of MongoDB via the default port 27017. We can also set some specific parameters for the URL:

Mongoose.conect (' Mongodb://username:[email protected]:p ort/databasename?options ... ');

Options

The Connect method can accept an options object

Mongoose.connect (URI, options);

Here is the Options key

    • DB-Set which database to connect to
    • Server-Set up a connection service instance
    • Replset-Set Connection Replset instance
    • User-Set Login username
    • Pass-Set the login user password
    • Auth-Validate options
    • Mongos-boolean If set to True the database is more reliable

For example:

var options = {  db: {native_parser:true},  server: {poolsize:5},  Replset: {rs_name: ' Myreplicasetname '} ,  User: ' MyUserName ',  Pass: ' MyPassword '}mongoose.connect (URI, options);

  

Mongoose Guide-Connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.