用猫鼬连接到Mlab

时间:2017-11-23 12:43:59

标签: node.js mongodb mlab

您好我正在尝试进行简单连接

mongoose.connect('mongodb://JFalcon:john2522@ds119476.mlab.com:19476/hidonshabat', {useMongoClient: true}, function(err){
    if(err) {
        console.log('Some problem with the connection ' +err);
    } else {
        console.log('The Mongoose connection is ready');
    }
})

正如您所看到的,这是网址! 请帮帮我

3 个答案:

答案 0 :(得分:1)

mongoose.connect('mongodb://localhost:27017/myapp', **{useNewUrlParser: true}**);

摘自官方文档:

  

useNewUrlParser-基础的MongoDB驱动程序已弃用其   当前的连接字符串解析器。因为这是一个重大变化,所以他们   添加了useNewUrlParser标志,以允许用户使用旧的   如果他们在新的解析器中发现错误,则解析器。 您应该设置   useNewUrlParser:true ,除非它阻止您连接。注意   如果您指定useNewUrlParser:true,则您必须在   您的连接字符串,例如mongodb:// localhost:27017 / dbname。新的   网址解析器不支持没有   端口,例如mongodb:// localhost / dbname。

答案 1 :(得分:0)

请更正如下

@Entity
@Table(name="act_re_deployment")
public class ActivitiProcessDeployment implements Serializable{

    @OneToOne (cascade=CascadeType.ALL, mappedBy="deployment")
    private ActivitiProcessDefinition activitiProcessDefinition;
}

@Entity
@Table(name="act_re_procdef")
public class ActivitiProcessDefinition implements Serializable {

    @JsonIgnore
    @OneToOne
    @JoinColumn(name="deployment_id_", unique= true)
    private ActivitiProcessDeployment deployment;

    //remove this
    //@JsonProperty
    //@Column(name="deployment_id_")
    //private String deploymentId;

    @JsonProperty
    public int getDeploymentId(){
        return deployment.getId();
    }
}

答案 2 :(得分:0)

var Mongoose=require("mongoose");
var dbURI='mongodb://JFalcon:john2522@ds119476.mlab.com:19476/hidonshabat';
Mangoose.connect(dbURI,function(err){    
    if(err){
    console.log('Some problem with the connection ' +err)   
    } 
    else {
    console.log('The Mongoose connection is ready')  
    }

})
module.exports={Mongoose};