mohamed mellouki
mohamed mellouki

Reputation: 613

Querying local users collection

when i check for specific user in Meteor.users collection i get an object with a lot of imformation that i do not need

var checkResults = Meteor.users.find({username: "aaa"});
    (checkResults) ? Meteor._debug(checkResults) : Meteor._debug("nothing");

Results :

collection
    Object { docs={...}, next_qid=   3 , queries={...}, more...}

current_snapshot
     null

docs
    Object { af8e9611-62fe-4024-81d4-1365e02992bb={...}, 5ba9f289-7fa6-4dd0-ae30-802f0c4e3138={...}}

             5ba9f289-7fa6-4dd0-ae30-802f0c4e3138 

    Object { _id= "5ba9f289-7fa6-4dd0-ae30-802f0c4e3138", username= "aaa" }

             af8e9611-62fe-4024-81d4-1365e02992bb

    Object { _id="af8e9611-62fe-4024-81d4-1365e02992bb", emails=[1], username= "ddd" }

next_qid
    3


paused
    false


queries
    Object { 1={...}, 2={...}}

_modifyAndNotify
    function()

find
    function()

findOne
    function()

insert
    function()

pauseObservers
    function()

remove
    function()

restore
    function()

resumeObservers
    function()

snapshot
    function()

update
    function()

__proto__
    Object { find=function(), findOne=function(), insert=function(), more...}

cursor_pos
    0


db_objects
    null


limit
    undefined


reactive
    true


skip
    undefined


sort_f
    null


_getRawObjects
    function()

_markAsReactive
    function()

count
    function()

fetch
    function()

forEach
    function()

map
    function()

observe
    function()

rewind
    function()

selector_f
    function()

__proto__
    Object { rewind=function(), forEach=function(), map=function(), more...}

I can access them by :

  checkResults.collection.docs[x].username 

but its not practical since i need to do process the results

is there anyway to get a precise object for the query without the extra info?

Upvotes: 0

Views: 1922

Answers (1)

davidwen
davidwen

Reputation: 125

Meteor.users.findOne({username: 'aaa'}) returns the first user document (in this case, it should be unique) if it exists and returns undefined otherwise.

If you wanted to retrieve everything that matches a query without the extra cursor information, you could do something like Meteor.users.find({username: 'aaa'}).fetch()

See http://docs.meteor.com/#findone and http://docs.meteor.com#find

Upvotes: 3

Related Questions