mongodb queries both with AND and OR

后端 未结 4 1928
情歌与酒
情歌与酒 2020-12-13 00:10

can I use combination of OR and AND in mongodb queries?

the code below doesn\'t work as expected

db.things.find({
           $and:[
                {         


        
4条回答
  •  离开以前
    2020-12-13 00:24

    I believe $and is only supported in MongoDB v2.0+. I'm surprised that the console accepted the expression in the first place. I'll try to recreate against a 1.8 server I have.

    Also check 10Gen's Advanced Query Documentation for $and.

    Update

    I entered your sample data into both a v1.8x and v2.0x MongoDB server. The query works on the v2.0x and fails on the v1.8x. This confirms my (and Miikka's) suspicions that the problem is with $and and your server version.

    I found a (arguably) clever workaround for this on the Web here. I hope this helps.

    -SethO

提交回复
热议问题