我刚开始航行Js和mongodb。我绝对是个新手。
问题:我已经在我的mongodb数据库上有了一个用户集合。我想把它连接到sails上,以显示收藏列表。
我看过帆船杂志的文件。我已经安装了sails适配器并编辑了connection.js.
module.exports = {
// this is my model
attributes: {
firstname: {
type: 'string'
}
},
findUser: function(opts,callback){
///// How am I going to connect to mongo and query the users ?
//// user.find('John Doe') wont work here.
}
}发布于 2016-04-12 07:06:19
npm install sails-mongoconfig/connections.js取消评论部分,并输入必要的信息
someMongodbServer:{适配器:'sails-mongo',主机:'mongohost.com',端口: 55915,用户:'user',密码:‘密码’,数据库:'dbname‘},config/models.js中输入连接适配器变量
..。连接:“某个蒙突服务器”.编辑:为了从数据库中获取数据,请使用以下方法:
User.find({firstname: 'John Doe'}).exec(function(error, user) {
console.log(user);
});https://stackoverflow.com/questions/36564388
复制相似问题