簡體   English   中英

無法訪問或使用mongo db終端中顯示的文檔

[英]Cannot access or use documents showing in mongo db terminal

我創建了一個名為Stampest的集合,該集合存儲用戶創建的上載圖像的引用和標題字符串。 使用ostrio:autoform包。 這個包創建了一個名為Images的集合,所有用戶上傳的圖像都存儲在其中,並引用/來自它們。

當我在終端中查詢mongo時使用

db.stampest.find({})

我收到了條目

在此處輸入圖片說明

這表明數據庫中的Stampest Collection中有文檔。 但是問題是,當我在Meteor Toys調試中查看集合時,它說是空的,並且當我插入一個文檔(在這種情況下,是圖像和標題)時,該集合變為1表示瞬間,然后返回地理到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>

根據我在代碼中看到的內容,您將在代碼中返回一個db項Array ,而不是Cursor 如果查看https://docs.meteor.com/api/pubsub.html ,您會注意到常規publications返回簡單游標或游標數組,但不會返回您獲取的數據。

編輯:同樣,您出版物中的console.log將永遠不會被解釋,因為它在前一行返回。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM