I have a question for all of the JS and Meteor experts on here.
I realized today that all throughout my app I reference a DB document as follows:
//define a const from the db
const usr = Meteor.users().findOne(id);
//and then create an object based off of the fields on the document
const userObj = {
name: usr.fn,
picture: usr.pic
};
So I was realizing that the usr
that was defined inhereted ALL of the properties of the DB document, when I only used TWO of the properties to define my userObj
.
My question is: would it be much more performant if i specified fields in query of the usr
declaration? Or does it not make much of a difference?
I would basically change it to this:
const usr = Meteor.users.findOne(id, {fields: {fn: 1, pic: 1}});
I am sure it would help somewhat, but would it be worth it for me to go back through every declaration like this and “optimize” it with fields
?? I really don’t know how expensive defining a variable with a large object is.
Thanks in advance