I'm running a GraphQL-Node.js-Mongo Application. I need to return all the documents upon some conditions. But I'm confused with .find() method as it requires async and await, or a callback as it's parameter. Here my code...
getChatsOfUserAboutProduct: {
type: sampleChat, //it has been declared already
args: {
userID: { type: GraphQLString },
pID: { type: GraphQLString }
},
resolve(parent, args) {
//The below MySQL query I can compare..!
//SELECT * FROM chats WHERE productID='' AND (senderID='' OR recieverID='')
return Chat.find({productID:args.pID,$or: [{senderID: args.userID },{receiverID: args.userID}]});
//Chat is a pre-defined model (via Mongoose)
}
}
How to get the returned documents from .find() method of Mongoose?