0

I am doing something wrong in my Meteor app but simply cannot find out what it is. I'm not receiving any data in the UI. Here's the code.

lib/common.js

Data = new Meteor.Collection('data2');

'data2' is a collection I created and responds fine in mongo shell

server/app.js

Meteor.publish("Data", function() {
        return Data.find({});
    });

client/app.js

Meteor.subscribe("Data");

client/helpers.js

Template.home.helpers({

    results: function(){
     return Data.find();

}
});

I've even tried with specifying the two columns-field1, 2 in find() to no avail.

client/home.html

<template name="home">
<table class="table table-striped tablesorter z-depth-5">
    <thead>
            <tr>
              <th width="15%">field1</th>
              <th width="15%">field2</th>
            </tr>
    </thead>
    <tbody>
            {{#each results}}
            <tr>
            <td>{{field1}}</td>
            <td>{{field2}}</td>          
            </tr>
            {{/each}}
    </tbody>
  </table>

Inspection findings -

Data.find().fetch()
[]
hct1906
  • 41
  • 6
  • Just for grins do `Meteor.publish('myData',...)` and `Meteor.subscribe('myData')` to rule out problems with multiple uses of the name `Data` – Michel Floyd Aug 24 '15 at 02:48
  • Changed 'Data' var to 'myData' - still no dice. – hct1906 Aug 24 '15 at 02:53
  • `Meteor.Collection` is now `Mongo.Collection`, though this isn't your problem. When you say "Inspection findings" do you mean you ran that in the web console? – David Weldon Aug 24 '15 at 02:58
  • I don't see anything obviously wrong in what you're doing. Try putting the *autopublish* package back in and see if the data shows up. Then you can narrow down the problem to your publication or subscription. – Michel Floyd Aug 24 '15 at 02:58
  • @DavidWeldon - yes - in web console. – hct1906 Aug 24 '15 at 02:59
  • @MichelFloyd - added it. No difference. – hct1906 Aug 24 '15 at 03:02
  • Do you get a record count from the mongo console? `db.data2.find().count()` – Mark Leiber Aug 24 '15 at 03:05
  • @MarkLeiber - 0 in web console and 4 in mongo shell (there are 4 docs in the DB) – hct1906 Aug 24 '15 at 03:10
  • Is there a way to check if Meteor is connecting with the DB? There is only one db - 'local' and i've done `set MONGO_URL= ` . Also tried with the url as ` mongodb:\\localhost\local `- but same results. – hct1906 Aug 24 '15 at 03:12
  • well that's got to be part of the problem; neither of these MONGO_URLs are valid. either not set it, or set it to `mongodb://127.0.0.1/something` – Christian Fritz Aug 24 '15 at 03:25
  • @ChristianFritz - tried it with `mongodb://127.0.0.1/local` as well as with nothing as in `set MONGO_URL= ` and with just `set MONGO_URL=mongodb://127.0.0.1 ` . Same thing. – hct1906 Aug 24 '15 at 03:34
  • Have you tried the solutions here?: http://stackoverflow.com/questions/10588038/how-to-use-the-existing-mongodb-in-a-meteor-project. Namely, `export MONGO_URL=mongodb://localhost:your_port/local` – Mark Leiber Aug 24 '15 at 03:41
  • @MarkLeiber - tried it. with both localhost and 127.0.0.1. Just checked - in MongoVue - the serverInfo shows Host as something else - like for example `ZBCD321YU` . Tried it with that host as well, nothing's working. Also, on `myData.find()` in the web console, I get `L…n.Cursor {collection: LocalCollection, sorter: null, _selectorId: undefined` with `data2` mentioned in that same web console tree - so it is able to go up to the `new Mongo.collection('data2')` but don't know if beyond that to the DB or something's not letting it subscribe? – hct1906 Aug 24 '15 at 04:06
  • Update: Set Mongo_url to a remote server and it works. (not trying with localhost for now). But now, it displays just 1 row whereas it should be displaying a dozen. What could be the issue? Everything's the same except for the mongo_url and Mongo.collection. (Would also like to point out that I am coming from a Python b/g and this is my 1st time with Meteor) – hct1906 Aug 24 '15 at 20:16

1 Answers1

0

Solved:

The mistake I was making was that I was calling the 'local' DB from the c:\data\db directory created when I installed mongodb on my system. But the meteor db is not located there but resides in /.meteor. Upon correction, it works.

hct1906
  • 41
  • 6