How to search for Id in mongodb With condition

0

How to do a mongo search with condition parameters, type:

Collection.find({userId}, {done: true}).fetch();

In this way, I want to return all the documents that have the done equal to true, searching the User id.

I have in the collection a userID , _id collection, and the done

I'm using Meteor and grahql, this is my solve

 Query: {
    async taskCompleted(obj, args, {userId}) {
        return await Tasks.find({userId}).fetch();
    }
}

In this code snippet, it returns all the tasks of the user in question

    
asked by anonymous 29.07.2018 / 20:55

1 answer

1

The correct denotation would be.

var user_id = "as23df56hg";

//retorna um array de Tasks do respectivo query
var tasks = Tasks.find({ "userId" : user_id, "done" : true }).fetch();

You can also use findOne

var user_id = "as23df56hg";

//retorna a primeira Task do respectivo query
var task = Tasks.findOne({ "userId" : user_id, "done" : true });

Important

Using Organization Selectors

Using Field Selectors

    
07.08.2018 / 11:03