question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select using a external collection

See original GitHub issue

If possible how could you populate a select (options property) with an external Mongo collection?

Here’s what I’ve tried so far:

import { Mongo } from 'meteor/mongo'
import Schema from 'simpl-schema'

import {api as PeopleApi} from './People' // a mongo collection

const peopleData = PeopleApi.find({}).fetch().map(obj => obj['name'])

export const api = new Mongo.Collection('Service')

export const schema = new Schema({
  name: {
    type: String,
    optional: false,
    label: 'Name'
  },
  person: {
    type: String,
    allowedValues: [...peopleData]
  },
  active: {
    type: Boolean,
    label: 'Active',
    defaultValue: true
  }
})

export default api

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

2reactions
aldeedcommented, Nov 30, 2017

@caiobep allowedValues (and most of the props) can be a function, which is then executed each time the allowedValues array is needed. (You can also call .map directly after find() without the fetch.)

export const schema = new Schema({
  person: {
    type: String,
    allowedValues() {
      return PeopleApi.find().map(obj => obj.name);
    }
  },
  // ...
})

Obviously you’ll need to make sure the PeopleApi subscription is ready before you validate if this is in client code.

1reaction
StanLindseycommented, Aug 21, 2017

Ah, in which case it may be because .find().fetch() returns a promise and isn’t resolved when you create the schema.

Read more comments on GitHub >

github_iconTop Results From Across the Web

External Collections - Duda Support
Click + New Collection, and select External Database. Type the Endpoint URL and click Fetch collection. Click Continue. Type a name for the...
Read more >
Use Microsoft Query to retrieve external data
To set up a data source by using Microsoft Query: On the Data tab, in the Get External Data group, click From Other...
Read more >
Velo: Adding and Deleting an External Database Collection
To add an external collection:​​ In the Velo sidebar click the plus sign next to Database and select Add External Collections.
Read more >
Adalo External User Collection Beta - Xano Community
I have been attempting to complete the external database and user authentication connection using Xano and Adalo.
Read more >
Formulas—ArcGIS Survey123 | Documentation
Use formulas to create smarter forms with Survey123. ... Returns the number of selected answers for select_one and select_multiple questions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found