How can I query a Mongo collection using Mongoose to find all documents that have a specific relationship between two of their own properties?
For example, how can I query collections charactersto find all those characters whose value is currentHitPointsless than their value maximumHitPoints? Or all those projectswho have currentPledgedMoneyfewer of them pledgeGoal?
I tried to do something like this:
mongoose.model('Character')
.find({
player: _currentPlayer
})
.where('status.currentHitpoints').lt('status.maximumHitpoints')
.exec(callback)
but I get errors as the argument ltshould be Number. The same thing happens if I use $.status.maximumHitpoints(I was hoping that Mongoose would be able to resolve it, as when performing assembly operations).
Is this something that can be done in a query? I would expect so, but I canβt figure out how to do this. Otherwise, I can filter the entire collection using underscore, but I suspect that this will have a negative impact on performance.
PS: I also tried using similar approaches with a findboneless call .
source
share