deyles-zz / sculejs

SculeJS - data structures for the web
165 stars 24 forks source link

Return Only 1 Field? #17

Closed senseiad closed 11 years ago

senseiad commented 11 years ago

Hi Dan

Trying to figure out how to only return one field from a find(), instead of the whole record/document?

I think in MongoDB you use {"name" : 1} where 1 is true.

Thanks

Adam

deyles-zz commented 11 years ago

Hey Adam,

SculeJS doesn't currently support this. There's really no additional overhead associated with returning the entire document since what's actually returned is a reference and not a copy of the object. No new data is being loaded (other than the pointer), and no data is transfered since everything is happening inside the same context in the JavaScript virtual machine.

Cheers, Dan

senseiad commented 11 years ago

Thanks Dan

Clearly this is a newbie question, but how do I then reference an individual field? Could you provide an example?

Sent from my iPhone

On 9 May 2013, at 12:08, dan-eyles notifications@github.com wrote:

Hey Adam,

SculeJS doesn't currently support this. There's really no additional overhead associated with returning the entire document since what's actually returned is a reference and not a copy of the object. No new data is being loaded (other than the pointer), and no data is transfered since everything is happening inside the same context in the JavaScript virtual machine.

Cheers, Dan

— Reply to this email directly or view it on GitHub.

deyles-zz commented 11 years ago

Hey Adam,

SculeJS documents are actually JavaScript objects, so accessing their fields uses the same notation as regular JavaScript code.

var scule = require('com.scule');
var collection = scule.factoryCollection('scule+dummy://test', {secret:'mysecret'});
var o = scule.find({i:{$gte:10}});
o.forEach(function(document) {
   console.log(document.i);
   document.i = 3;
   console.log(document.i);
});