[Resolved] Projection not working as expected in Method


#1

The following method:

  getDocBasic: function(docId) {
    var doc = Docs.findOne({ _id: docId}, { 'company.name' : 1 })
    console.log(doc);
    return doc;
  }

Gives me an object (doc) with the entire document in it (rather than just the company.name). So it seems the projection isn’t working at all. From what I can gather from the mongo docs this is unexpected. Meteor bug?

Edit: As soon as I ask I find the answer - syntax was incorrect: https://stackoverflow.com/questions/15961456/meteor-collection-find-always-returns-all-fields

  getDocBasic: function(docId) {
    var doc = Docs.findOne({ _id: docId}, {fields: { 'company.name' : 1 }})
    console.log(doc);
    return doc;
  }

#2

Use Docs.findOne({_id: docId}, {fields: {'company.name': 1});


#3

Thanks - seems I issued my edit slightly too late :slight_smile: