【问题标题】:ReactJS, MeteorJS, and MongoDB: Getting collection from different collection value?ReactJS、MeteorJS 和 MongoDB:从不同的集合值中获取集合?
【发布时间】:2017-03-14 04:19:39
【问题描述】:

好的,所以,我有一个带有函数 getPhotos() 的组件,它从父 props 中获取一个字符串:

import React, { Component, PropTypes } from 'react';

// data
import { Cats } from '../api/collections/galleries.js';

export default class...
 getPhotos() {
   let gallery = this.props.galleryName; // gallery = "Cats"

现在,我想使用这个字符串“Cats”从 mongo db 访问一个集合,所以我尝试使用 window["Cats"],但我不认为它在 window 对象上:

   let photoData = window[gallery].find().fetch(); // window[Cats] and window["Cats"] returns undefined
   return photoData;
}

meteor 中的一切似乎都在工作、发布和订阅。

任何想法我可以如何使用 React 组件来做到这一点?

【问题讨论】:

    标签: mongodb reactjs meteor


    【解决方案1】:

    你可以的

    Meteor.connection._stores[gallery]._getCollection().find().fetch();
    

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 2018-08-07
      相关资源
      最近更新 更多