Let’s say I have a Collection with two properties: amount and amountreceived that are decimals.
I want to write a query that will return items from the collection that meet the criteria of the amount being greater than the amount received.
Currently I have a javascript function that looks like this:
f = function() { return this.amount > this.amountreceived;}
I also have a collection set that looks like this:
item1 : amount = 50, amountreceived = 0;
item2 : amount = 50, amountreceived = 25;
If I run db.MyCollection.find(f) the only result returned is item1.
Any ideas on why that query will not return both results?
I’m assuming you are using the C# driver? Because BSON does not have a decimal data type the C# driver has to represent the .NET decimal value in some way. The default representation is as a string, which is good for not losing any precision but bad for doing queries.
You can also ask the C# driver to store .NET decimal values as BSON doubles, which would involve some loss of precision and could overflow, but would be good for queries.