Tracker.autorun not working inside componentDidMount of react when I specify the projection (fields) for output. But the same works when I dont have any projection on mongo query.
This works:
Meteor.subscribe('quotes');
this.quotesTracker = Tracker.autorun(() => {
const quotes = Quotes.find(
{instrument_token: 12374274},
{
sort: {timestamp: 1},
limit: 5000
}
).fetch();
This doesnt work
Meteor.subscribe('quotes');
this.quotesTracker =Tracker.autorun(() => {
const quotes = Quotes.find(
{instrument_token: 12374274},
{
fields: {
last_price: 1,
timestamp: 1,
},
sort: {timestamp: 1},
limit: 5000
}
).fetch();
What am I missing here?
I don't think Meteor's tracker works well with ReactJS, as their mechanism of re-render is different.
You might want to use this package.
https://github.com/meteor/react-packages/tree/devel/packages/react-meteor-data
You can use it like so.
Where
IndexPage
is your actual component.You can then access the db by
this.props.Meteor.collection.whatever.find()