【问题标题】:Cannot access or use documents showing in mongo db terminal无法访问或使用 mongo db 终端中显示的文档
【发布时间】:2016-12-02 20:29:09
【问题描述】:

我创建了一个名为 Stampest 的集合,其中存储了用户创建的上传图像和标题字符串的引用。使用ostrio:autoform package.This 包创建一个名为Images 的集合,其中存储所有用户上传的图像并因此引用/引用。

当我在终端中使用

查询 mongo
db.stampest.find({})

我得到了条目

这表明数据库中有文档,在Stampest 集合中。但是问题是当我在Meteor Toys调试中查看集合时,它说它是空的,当我插入一个文档时,在这种情况下,图像和标题,集合变为1 瞬间,geos 回到 0。终端或控制台没有错误

因此,我无法访问这些文档,我该怎么办?

这是 schema.js

Schemas = {};
Stampest  = new Meteor.Collection('stampest');

Stampest.allow({  
  insert: function (userId, doc) {
    return userId;
  },
  update: function (userId, doc, fields, modifier) {
    // can only change your own documents
    return doc.userId === userId;
  },
  remove: function (userId, doc) {
    // can only remove your own documents
    return doc.userId === userId;
  }
});


Schemas.Stampest = new SimpleSchema({
  title: {
    type: String,
    max: 60
  },
  picture: {
    type: String,
    autoform: {
      afFieldInput: {
        type: 'fileUpload',
        collection: 'Images',
        // uploadTemplate: 'uploadField' // <- Optional
        // previewTemplate: 'uploadPreview' // <- Optional
      }
    }
  }
});

Stampest.attachSchema(Schemas.Stampest);

publish是这样的:

Meteor.publish('stampest', function () {
    return Stampest.find({author: this.userId}).fetch();
     console.log(Stampest.find());
});

用户像这样插入imagetitle

<template name="createStamp">
    <div class="grid-block">
        <div class="grid-container">
            <div class="upload-img">
                <a href="{{file.link}}">{{file.original.name}}</a>
            </div>

            <div class="new-stamp-container">
            {{> quickForm collection="Stampest" type="insert" id="insertStampForm" class="new-stamp-form"}}
            </div>
        </div>  
    </div>
</template>

【问题讨论】:

  • 使用meteor mongo检查服务器。如果记录在那里,那将是您订阅数据的方式有问题

标签: mongodb meteor file-upload meteor-packages


【解决方案1】:

根据我在您的代码中看到的,您在代码中返回了一个 Array 的 db 项目,而不是一个 Cursor。 如果您查看https://docs.meteor.com/api/pubsub.html,您会注意到常规的publications 返回简单游标或游标数组,但从不返回您获取的数据。

编辑:此外,您出版物中的console.log 永远不会被解释为它返回上一行。

【讨论】:

    猜你喜欢
    • 2017-03-17
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    • 2015-09-12
    • 1970-01-01
    • 2011-12-04
    • 2021-11-02
    • 1970-01-01
    相关资源
    最近更新 更多