通过json对象字段中的属性进行mongoose搜索

时间:2015-05-18 04:42:20

标签: node.js mongodb mongoose

假设我有一个架构

Temp.find({location.country: {$in: ['US', 'CN', 'JP']}});

location将存储一个json对象

现在我想通过这个json对象字段中的属性进行搜索,我可以使用以下查询吗?

foreach (Control control in grpBxTargetSensitivity.Controls)
            {
                if (control is FlowLayoutPanel && control.HasChildren)
                {
                    foreach (Control ctrl in control.Controls)
                    {
                        if (ctrl is Panel && ctrl.HasChildren)
                        {
                            foreach (Control tbox in ctrl.Controls)
                            {
                                if (tbox is TextBox)
                                {
                                    TextBox textbox = tbox as TextBox;
                                    validData &= !string.IsNullOrWhiteSpace(textbox.Text);
                                }
                            }
                        }
                    }
                }
            }

1 个答案:

答案 0 :(得分:3)

是的,您可以使用the dot notation执行此操作,只需将其括在引号内:

Temp.find({"location.country": {$in: ['US', 'CN', 'JP']}}, function(err, data) { /* ... */});