Mongodb dot notation wildcard?

后端 未结 3 2013
自闭症患者
自闭症患者 2020-12-10 01:22

I have a collection of users, each of which may be subscribed to one or more services. Each service has some meta data, including the number of credits the user has for that

3条回答
  •  醉话见心
    2020-12-10 01:40

    I don't know of a way to accomplish this using the schema you're using. It seems to me you're abusing objects as arrays. If services were an array (the plural hints that it should be), you could simply query

    db.users.find({"services.credits" : { $lt : 50 }}); 
    

    or use $elemMatch if you need to match multiple conditions on a single array element.

提交回复
热议问题