Returning specific fields with elementCriteriaModel I'm writing a plugin that adds or updates users profiles in Craft from a JSON file. Every user profile could have a lot of custom fields in the future which store a lot of data.
To check if a user exist and if its data is up to date with the data in the JSON file, I need to retrieve 2 fields from every user profile. Is that possible with the elementCriteriaModel?

I've seen examples of the criteriaModel by which you filter which users are returned by adding parameters. And then you get an array back filled with users that match the criteria and all of their custom fields.

But I need all users returned, but not with all their custom fields. Because I think that will slow things down.
Is it possible to fetch all users but returning only 2 specific fields by using the criteria model? Or some other way?
I know I can filter the results afterwards and return another array, but then the slow database query is allready been made. I want to limit the amount of queries made and the amount of data retrieved to the bare necessities.
Not 100% certain, but I suspect that with a standard ElementCriteriaModel it's all or nothing, as craft generally returns the full userModel including all custom fields. If you're worried about memory limitations, then you might want to either process the users in batches and/or create your own custom query. Something like this perhaps:

// define query
$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::User);

$query = craft()-&gt;elements-&gt;buildElementsQuery($criteria);
$query-&gt;select(array('elements.id AS id', 'field_extid AS extid', 'field_lastupdatetime AS lastupdatetime'));
$query-&gt;limit(null);
$results = $query-&gt;queryAll();

foreach($results as $result)
{
    // compare craft values to json

    // var_dump($result['extid']) // uncomment to test
    // var_dump($result['lastupdatetime']) // uncomment to test
    // set $userExists equal to true or false if needed

    // create/retrieve user
    if ($userExists) {
        $user = craft()-&gt;users-&gt;getUserById($result['id']);
    } else {
        $user = new UserModel();
    }

    // update, save, etc
    // ...
}


You can also use var_dump($results) to test whether you are getting the expected results.