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