English 中文(简体)
Mongodb dot notation Wildcard?
原标题:Mongodb dot notation wildcard?

我有一批用户,每个用户可以订阅一个或多个服务。 每个部门都有一些元数据,包括用户为这一服务提供的信贷数量。

如果我无法知道哪项服务目标是什么关键,那么我怎么能找到所有用户对象,如果这些用户的某种服务信用不足50个?

从概念上讲,这样做是一样的。

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

用户收集:

   {
_id: 4f0ea25072139e4d2000001f,
services : {
    a : { credits : 100, score : 2000 },
    b : { credits : 200, score : 300 },
    c : { credits : 10, score : 1300 }
    }
},
{
_id: 4f0ea25072139e4d2000001f,
services : {
    f : { credits : 68, score : 14 },
    q : { credits : 1000, score : 102 },
    z : { credits : 59, score : 352 }
    }
}

在此,我所想做的另一个例子就是:。 http://www.mongodb.org/display/DOCS/Advanced+Queries#comment-3460758 <54/a>

问题回答

这是对你问题的实际答案。

如果你无法知道服务对象的关键是什么,那么你怎么能够找到所有用户物体,如果这些用户的某种服务信用不足50个。

使用一个美元地点:

db.users.find({
    $where: function () {
        for (var index in this.services)
            if (this.services[index].credits < 50)
                return this;
    }
});

我不知道用你重新使用的图象来实现这一目标。 在我看来,你似乎把燃烧物体作为阵列。 http://www.un.org 这是一种阵列(应该说的复数背面),你可以简单地质疑。

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

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





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

pdo database abstraction

Can someone help me to see what is going wrong with this setup I build the @sql query in the function below like this. The extra quotes are setup in the conditions array. $sql .= " WHERE $...

I wish I could correlate an "inline view"

I have a Patient table: PatientId Admitted --------- --------------- 1 d/m/yy hh:mm:ss 2 d/m/yy hh:mm:ss 3 d/m/yy hh:mm:ss I have a PatientMeasurement table (0 to ...

Syntax help! Php and MYSQL

Original: $sql = "SELECT DATE(TimeAdded) AS Date, $column_name FROM Codes ORDER BY TimeAdded ASC"; Altered: $sql = "SELECT DATE("m", TimeAdded ) AS Date, ColumnName FROM TableName ORDER BY ...

Is this code Equivalent

I am not a fan of the following construction if (self = [super init]) { //do something with self assuming it has been created } Is the following equivalent? self = [super init]; if (self != ...

热门标签