Hi all !
I have a project of create a MCQ app. I’m having trouble connecting to mongodb, and it’s preventing me from moving forward with my project. I found several sources on the internet that talked about removing autopublish, which I did, and I also followed the tutorials on publishing and subscribing.
Now, my application is unable to connect to a database (I changed the MONGO_URL variable). I changed the variable because I want to connect to an existing database.
I can guarantee you that the database exists, the collection exists and the data is filled in.
I’m on Windows 10 2004.
> echo %MONGO_URL%
mongodb://localhost:27017/mydb
I probably make a mistake and I don’t see it, I’d just like to understand why I make that mistake so I don’t make it again.
My code (I followed the template with the meteor create --full
command).
'/api/qcm/qcm.js'
import { Mongo } from 'meteor/mongo';
export const DB_QCM = new Mongo.Collection('qcm');
if (Meteor.isServer) {
// This code only runs on the server
Meteor.publish('qcm', function qcmPublication() {
return DB_QCM.find();
});
}
Meteor.methods({
'qcm.insert'(title, url) {
check(url, String);
check(title, String);
return DB_QCM.insert({
url,
title,
createdAt: new Date(),
});
},
});
And as I saw somewhere, subscribing when the main page is loaded:
'startup/client/routes.js'
FlowRouter.route("/", {
name: "App.home",
action() {
BlazeLayout.render("App_body", { main: "App_home" });
},
waitOn: function(){
return Meteor.subscribe("qcm");
}
});
And the server register-api file :
'startup/server/register-api.js'
import '../../api/qcm/qcm.js';
On Chrome 83, here is my response when I search for DB_QCM :
The code using it :
'ui/pages/qcmpage/qcmpage.js'
import { Template } from 'meteor/templating';
import { DB_QCM } from "../../../api/qcm/qcm.js";
Template.QCM_Home.onCreated(function qcmHomeOnCreated() {
this.state = new ReactiveDict();
Meteor.subscribe('qcm');
});
Template.QCM_Home.helpers({
qcms() {
return DB_QCM.find();
},
});
I searched everywhere but I haven’t found an answer that fits my problem.
What is wrong, and why ?
Nico