[solved] Why Mongo.Collection won't create mongo db?


#1

When I’m trying to create mongodb using collection2
with this line of code

Projects = new Mongo.Collection("projects");
it didn’t do anything.

I tried to find the “projects” in mongo using “show collection”, and it isn’t there.

btw My code is in meteor project directory not in client and server
`Projects = new Mongo.Collection(“projects”);

CustomerGain = new SimpleSchema({
desc:{
type: String,
label:“Description”
},
author:{
type:String,
label: “Author”,
autoValue: function(){
return this.userId;
},
autoform:{
type:“hidden”
}
},
createdOn:{
type: Date,
label:“Created On”,
autoValue:function(){
return new Date();
},
autoform:{
type:“hidden”
}
}
})

CustomerPain = new SimpleSchema({
desc:{
type: String,
label:“Description”
},
author:{
type:String,
label: “Author”,
autoValue: function(){
return this.userId;
},
autoform:{
type:“hidden”
}
},
createdOn:{
type: Date,
label:“Created On”,
autoValue:function(){
return new Date();
},
autoform:{
type:“hidden”
}
}
})

CustomerJob = new SimpleSchema({
desc:{
type: String,
label:“Description”
},
author:{
type:String,
label: “Author”,
autoValue: function(){
return this.userId;
},
autoform:{
type:“hidden”
}
},
createdOn:{
type: Date,
label:“Created On”,
autoValue:function(){
return new Date();
},
autoform:{
type:“hidden”
}
}
})

ValuePropositionSchema = new SimpleSchema({
name:{
type:String,
label: “Name”,
},
desc:{
type:String,
label: “Description”
},
Gain:{
type: [CustomerGain]
},
Pain:{
type: [CustomerGain]
},
Job:{
type: [CustomerGain]
},
author:{
type:String,
label: “Author”,
autoValue: function(){
return this.userId;
},
autoform:{
type:“hidden”
}
},
createdAt:{
type:Date,
label: “Created At”,
autoValue: function(){
return new Date();
},
autoform:{
type:“hidden”
}
}
});

ProjectSchema = new SimpleSchema({
name:{
type:String,
label: “Name”,
},
desc:{
type:String,
label: “Description”
},
ValueProposition:{
type:[ValuePropositionSchema]
},
owner:{
type:String,
label: “Owner”,
autoValue: function(){
return this.userId;
},
autoform:{
type:“hidden”
}
}
});

Projects.attachSchema(ProjectSchema);
`


#2

it turns out when I’m using autoform It requires a field, so , I set to optional: true.

Problem Solved.