stijnsanders / TMongoWire

Delphi MongoDB driver
MIT License
102 stars 37 forks source link

$and operator query #39

Closed scaleman114 closed 7 years ago

scaleman114 commented 7 years ago

Hi, I wonder if you could possibly provide me an example of using the $and operator in a query? I am looking for something like: d := BSON(['customer.custNo',4000,$and[BSON(['allocated',TRUE]))]) Tried a few ways but just can't get it to work. Thanks for all your previous help.

stijnsanders commented 7 years ago

If I read this correctly, $and takes an array. And in the mean time I've changed TMongoWire to use jsonDoc so it's JSON instead of BSON now. It has a different syntax to embed documents. I'm not sure 'customer.custNo' as a key will work, so I've split that here also:

d:=JSON(['$and',VarArrayOf([JSON(['customer{','custNo',4000,'}']),JSON(['allocated',true])]);

Let me know if this works for you.

scaleman114 commented 7 years ago

Thanks again! I am still using BSON as I am trialling Rice.Mongo framework, so this works for me: d:=BSON(['$and',VarArrayOf([BSON(['customer.custNo',4297]),BSON(['allocated',false])])]);

stijnsanders commented 7 years ago

And it works with the 'customer.custNo' key? Great, good to know.