{"action":"created","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/3472","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/3472/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/3472/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/3472/events","html_url":"https://github.com/Automattic/mongoose/issues/3472","id":111932693,"number":3472,"title":"Possibility to pass Promise in Query conditions","user":{"login":"googoid","id":4312868,"avatar_url":"https://avatars.githubusercontent.com/u/4312868?v=3","gravatar_id":"","url":"https://api.github.com/users/googoid","html_url":"https://github.com/googoid","followers_url":"https://api.github.com/users/googoid/followers","following_url":"https://api.github.com/users/googoid/following{/other_user}","gists_url":"https://api.github.com/users/googoid/gists{/gist_id}","starred_url":"https://api.github.com/users/googoid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/googoid/subscriptions","organizations_url":"https://api.github.com/users/googoid/orgs","repos_url":"https://api.github.com/users/googoid/repos","events_url":"https://api.github.com/users/googoid/events{/privacy}","received_events_url":"https://api.github.com/users/googoid/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Automattic/mongoose/labels/help","name":"help","color":"FFFFFF"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-10-17T00:14:43Z","updated_at":"2015-10-19T02:16:37Z","closed_at":null,"body":"Hey folks,\r\n\r\nI have a habit of returning Query in my model methods. It gives me ability to chain my model methods and what's the best thing for me is using `select()` in my routes.\r\n\r\nUnfortunately I can't do the following thing:\r\n\r\n*schema.coffee*\r\n\r\n```coffee\r\nmongoose = require 'mongoose'\r\n\r\nmodule.exports = SomeSchema = new goose.Schema\r\n\tsomeString: String\r\n\tsomeOtherString: String\r\n\tsomeNumber: Number\r\n```\r\n*model.coffee*\r\n\r\n```coffee\r\n_ = require 'lodash'\r\nmongoose = require 'mongoose'\r\nSomeSchema = require './schema.coffee'\r\n\r\n_.extend SomeSchema.statics,\r\n\tfindSomeRecordsBySomeNumber: (someNumber) ->\r\n\t\tmongoose.model 'SomeModel'\r\n\t\t.find\r\n\t\t\tsomeNumber: someNumber\r\n\t\t\tsomeString: @_somePrivatePromisedThingy()\r\n\r\n\tfindTotallyDifferentThing: (someNumber) ->\r\n\t\t@findSomeRecordsBySomeNumber someNumber\r\n\t\t.where 'someOtherString'\r\n\t\t.equals 'some value'\r\n\r\n\t_somePrivatePromisedThingy: (reallyWantIt = false) ->\r\n\t\tnew Promise (resolve, reject) ->\r\n\t\t\tif not reallyWantIt\r\n\t\t\t\treturn reject new Error 'but you have to'\r\n\r\n\t\t\tdoSomeAsyncStuff (err, result) ->\r\n\t\t\t\tif err\r\n\t\t\t\t\treturn reject err\r\n\t\t\t\tresolve result\r\n\r\n\r\nmongoose.model 'SomeModel', Schema\r\n```\r\n\r\n*main.coffee*\r\n\r\n```coffee\r\nmongoose = require './mongoose'\r\n\r\nmongoose.model 'SomeModel'\r\n.create\r\n\tsomeString: 'hello'\r\n\tsomeOtherString: 'other string'\r\n\tsomeNumber: 9\r\n.then ->\r\n\tpromise = mongoose.model 'SomeModel'\r\n\t.findSomeRecordsBySomeNumber 9\r\n\t.select 'someOtherString'\r\n.then (model) ->\r\n\tconsole.log model.toObject() # contains only '_id' and 'someOtherString'\r\n```\r\n\r\nThe problem here is that if I resolve promise before calling `find()` I won't be able to return `Query` object.\r\n\r\nAny thoughts if currently there is a way of doing this?\r\n\r\nThanks in advance.\r\n"},"comment":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/comments/149078928","html_url":"https://github.com/Automattic/mongoose/issues/3472#issuecomment-149078928","issue_url":"https://api.github.com/repos/Automattic/mongoose/issues/3472","id":149078928,"user":{"login":"vkarpov15","id":1620265,"avatar_url":"https://avatars.githubusercontent.com/u/1620265?v=3","gravatar_id":"","url":"https://api.github.com/users/vkarpov15","html_url":"https://github.com/vkarpov15","followers_url":"https://api.github.com/users/vkarpov15/followers","following_url":"https://api.github.com/users/vkarpov15/following{/other_user}","gists_url":"https://api.github.com/users/vkarpov15/gists{/gist_id}","starred_url":"https://api.github.com/users/vkarpov15/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkarpov15/subscriptions","organizations_url":"https://api.github.com/users/vkarpov15/orgs","repos_url":"https://api.github.com/users/vkarpov15/repos","events_url":"https://api.github.com/users/vkarpov15/events{/privacy}","received_events_url":"https://api.github.com/users/vkarpov15/received_events","type":"User","site_admin":false},"created_at":"2015-10-19T02:16:37Z","updated_at":"2015-10-19T02:16:37Z","body":"It'll return the query object, which will let you further modify the query object. I guess I'm not understanding the issue you're having, can you please clarify?"}}