{"action":"opened","issue":{"url":"https://api.github.com/repos/edwardhotchkiss/mongoose-paginate/issues/75","labels_url":"https://api.github.com/repos/edwardhotchkiss/mongoose-paginate/issues/75/labels{/name}","comments_url":"https://api.github.com/repos/edwardhotchkiss/mongoose-paginate/issues/75/comments","events_url":"https://api.github.com/repos/edwardhotchkiss/mongoose-paginate/issues/75/events","html_url":"https://github.com/edwardhotchkiss/mongoose-paginate/issues/75","id":126295870,"number":75,"title":"Sorting/Searching populated documents as well as paginate","user":{"login":"dolanmiu","id":2917613,"avatar_url":"https://avatars.githubusercontent.com/u/2917613?v=3","gravatar_id":"","url":"https://api.github.com/users/dolanmiu","html_url":"https://github.com/dolanmiu","followers_url":"https://api.github.com/users/dolanmiu/followers","following_url":"https://api.github.com/users/dolanmiu/following{/other_user}","gists_url":"https://api.github.com/users/dolanmiu/gists{/gist_id}","starred_url":"https://api.github.com/users/dolanmiu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dolanmiu/subscriptions","organizations_url":"https://api.github.com/users/dolanmiu/orgs","repos_url":"https://api.github.com/users/dolanmiu/repos","events_url":"https://api.github.com/users/dolanmiu/events{/privacy}","received_events_url":"https://api.github.com/users/dolanmiu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-01-12T22:45:01Z","updated_at":"2016-01-12T22:45:01Z","closed_at":null,"body":"I have an ```Item``` collection which shows details about the items gets updated very frequently with different prices.\r\n\r\nI also have an ```InventoryItem``` collection which represents a real item which references then Item collection. It will have its ```assetId```, who owns it, which bot its in etc.\r\n\r\nNow I am making a store which I will stock all these ```InventoryItem```s in.\r\n\r\nHere is the Schemas for ```Item``` and ```InventoryItem```:\r\n\r\n```Item``` Schema:\r\n\r\n    var ItemSchema = new mongoose.Schema({\r\n        item: {\r\n            marketName: String,\r\n            model: String,\r\n            set: String,\r\n            exterior: String\r\n        },\r\n        price: {\r\n            currency: String,\r\n            custom: Number,\r\n            steam: Number\r\n        },\r\n        quantity: Number,\r\n        blacklist: {\r\n            type: Boolean,\r\n            default: false\r\n        },\r\n        custom: Boolean,\r\n        iconUrl: String\r\n    });\r\n\r\n```InventoryItem``` Schema:\r\n\r\n    var InventoryItemSchema = new mongoose.Schema({\r\n        item: {\r\n            type: mongoose.Schema.Types.ObjectId,\r\n            ref: 'Item'\r\n        },\r\n        assetId: String,\r\n        location: String,\r\n        bot: {\r\n            type: mongoose.Schema.Types.ObjectId,\r\n            ref: 'Bot'\r\n        },\r\n        user: {\r\n            type: mongoose.Schema.Types.ObjectId,\r\n            ref: 'User'\r\n        }\r\n    });\r\n\r\nNow the problem arises when I try and search ```InventoryItem``` by ```name```, or sort by ```price```, because ```name``` and ```price``` is inside the ```Item``` collection.\r\n\r\nI can't copy ```price``` from an ```Item``` into ```InventoryItem``` because as I said, the ```price``` updates frequently, and there will be multiple of the same ```Item```.\r\n\r\nPopulation is a solution, but I would need to sort/find after populating, which I do not believe is possible.\r\n\r\nThe store will have potentially thousands of items, so the data needs to be paginated. I am using ```mongoose-paginate``` to deal with that.\r\n\r\nHow would I do this? I am very stumped.\r\n\r\n"}}