繁体   English   中英

如何从浏览器控制台查询我的MongoDB集合?

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

我正在尝试将代码插入到MongoDB集合中的代码:

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
        });
    }
});     

}

我不知道此代码是否成功-它没有在命令提示符或浏览器控制台中引发任何错误,但是,特别是由于我在猜测/实验什么可能起作用,因此我想验证文档是否正确在继续下一步之前添加非硬编码的字段值。

因此:如何从浏览器控制台查询我的MogoDB集合?

我尝试了以下两件事:

timeAndSpace.find()
return timeAndSpace

...但是都无法显示任何数据,而且大多数都会在控制台中引发错误。

我希望这可以帮助您。

TimeAndSpace.find().fetch()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM