How can I query my MongoDB collection from the browser console?

I'm experimenting with code to insert a record into a MongoDB collection:

TimeAndSpace = new Mongo.Collection('timeAndSpace');

if (Meteor.isClient) {
    Template.addTimeSpaceForm.events({
        'submit form': function() {
            event.PreventDefault();
            var city = "Fort Bragg";
            var state = "California";
            var yearin = 1958;
            var yearout = 1959;
            Meteor.call('insertLocationData', city, state, yearin, yearout);
        }
    });

}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });

  Meteor.methods({
    'insertLocationData': function(city, state, yearin, yearout) {
        TimeSpaceCollection.insert({
            ts_city: city,
            ts_state: state,
            ts_yearin: yearin,
            ts_yearout: yearout
        });
    }
});     

}

I don't know if this code was successful - it did not throw any errors in the command prompt or in the browser console but, especially since I'm sort of guessing/experimenting about what might work, I want to verify the document was actually inserted before I proceed to the next step of adding non-hardcoded field values.

So: how can I query my MogoDB collection from the browser console?

I tried the following two things:

timeAndSpace.find()
return timeAndSpace

...but neither show me any data, and most throw errors in the console.

Upvotes: 0

Views: 180

Answers (1)

Max
Max

Reputation: 300

I hope this can help you out.

TimeAndSpace.find().fetch()

Upvotes: 1

Related Questions