Thinkjs Connecting MongoDB

Source: Internet
Author: User

  

1' Use strict ';2 /**3 * DB config4 * @type {Object}5  */6Module.exports = {7Type: "MONGO",8Log_sql:true,9Log_connect:true,Ten Adapter: { One MySQL: { AHost: ' 127.0.0.1 ', -Port: ", -Database: ", theUser: ", -Password: ", -Prefix: ' THINK_ ', -Encoding: ' UTF8 ' +          }, - MONGO: { +Prefix: ' THINK_ ', A             database: ' Larry ',//This is the name of the metabase to configure  atEncoding: ' UTF8 ', -Nums_per_page:10, -Log_sql:true, -Log_connect:true, - cache: { -Ontrue, inType: ', -timeout:3600 to             }, + options: { -                 //authsource: ' admin ' the             } *         } $     }Panax Notoginseng};

Whim want to try Thinkjs operation MongoDB, go to the official document looked, the default is only to the configuration of MySQL, the source code is not configured MONGO, only an official case, according to its db.js configuration copied to my own code, or unsuccessful.

Finally found that the reference to MySQL configuration is possible (do not blame me silly ....) Novice.... )。

In accordance with the official documentation, I take the following steps:

THINKJS Model User--mongo

After generating the user.js, write the following lines of code

User.js
' Use strict '; /* */= Think.model (' MONGO ', {function () {var ret This . Add ({ name:date () }); Console.log (this. Getmodelname (),this. db ()); return ret; });

Indexaction.js
function (self) { console.log. Model (' user '). AddUser ()); return Self.display (); }

Finally found log out of the DB information, the default is to connect to the Admin database .... Then try to add the MONGO configuration item to the database field, modify it to your own, and then actually succeed ~. It was a dejected, an afternoon.

Reference connection

Https://thinkjs.org/zh-cn/doc/2.1/model_config.html

Thinkjs Connecting MongoDB

Related Article

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.