Sean Ragsdale Sean Ragsdale - 2 months ago 8
Javascript Question

Return single value from a collection document in Meteor

I am trying to retrieve a single value from a Meteor collection document to use in a three.js scene. I want to be able to create a three.js object that uses variables from the database. These variables are static for now.

What I have is a three.js scene in Template.home.rendered. I have created a "Part" collection and made all data available to both client and server. There is a single data fixture (document) with

Part.insert({ name: "myPart", val: 75 });
.

I would like to able to return the value of the "val" field as a variable in the three.js scene like such
var size = Part.findOne(Part.val);
. However, the variable returns undefined. The data has been successfully written to the database and the browser cache. What am I missing?

Answer
size = Part.findOne({name:"myPart"}).val;