Mongo查询从json条目创建子表单

时间:2015-05-11 04:44:34

标签: json mongodb

我想只访问文档的一部分。下面给出的条目中只有变量,格式如下。

Document1:{
        "META" : {
            "CATEGORY" : "Boxes",
            "CREATEDBY" : "Garima",
            "PRIVACY" : "PUBLIC",
            "KEYWORDS" : [ 
                "day","night"
            ],
            "TEMPLATE_NAME" : "Name",

        "IS_ACTIVE" : true
    },
    "**Variables**" : **[ 


 {

            "INDEX" : 0,
            "DATATYPE" : "string",
            "NAME" : "varient text  type",

        }, 
        {

            "INDEX" : 1,
            "DATATYPE" : "number",
            "NAME" : "varient number type",

        }, 
        {

            "INDEX" : 2,
            "DATATYPE" : "price",
            "NAME" : "varient price type",

        }, 
        {

            "INDEX" : 3,
            "DATATYPE" : "date",
            "NAME" : "varient date type",

        }, 
        {

            "INDEX" : 4,
            "DATATYPE" : "text",
            "NAME" : "varient textarea type",

        }, 
        {

            "INDEX" : 5,
            "DATATYPE" : "string",
            "NAME" : "varient blank radio type",

        }, 
        {

            "INDEX" : 6,
            "DATATYPE" : "string",
            "NAME" : "varient single radio type",

        },**

需要输出

**Variable Names [varient text type,varient number type,varient price type,varient date type,varient textarea type,varient blank radio type,varient single radio type]**

我使用过db.collection.find({Variables})但没有显示,因为它是一个数组。 后来我希望这些名称使用autoform

在meteor中创建一个表单

2 个答案:

答案 0 :(得分:1)

JS文件:

var variant=CollectionName.find( { "VARIENTS.NAME": 1, _id : 0 } );

HTML文件:

          {{#each variant}}
            <li>
              {{#each VARIENTS}}
           {{this.NAME}}
           {{/each}}
            </li>
           {{/each}}

这将仅显示变体名称。

答案 1 :(得分:0)

您想要的输出和样本数据不匹配。

这是你在找什么 -

db.collectionName.find({},{"Variables.INDEX":1,"Variables.DATATYPE":1,"Variables.NAME":1, "_id":0})

以上查询将提供以下输出,并提供相关的样本数据。

{
    "Variables" : [
        {
            "INDEX" : 0,
            "DATATYPE" : "string",
            "NAME" : "varient text  type"
        },
        {
            "INDEX" : 1,
            "DATATYPE" : "number",
            "NAME" : "varient number type"
        },
        {
            "INDEX" : 2,
            "DATATYPE" : "price",
            "NAME" : "varient price type"
        },
        {
            "INDEX" : 3,
            "DATATYPE" : "date",
            "NAME" : "varient date type"
        },
        {
            "INDEX" : 4,
            "DATATYPE" : "text",
            "NAME" : "varient textarea type"
        },
        {
            "INDEX" : 5,
            "DATATYPE" : "string",
            "NAME" : "varient blank radio type"
        },
        {
            "INDEX" : 6,
            "DATATYPE" : "string",
            "NAME" : "varient single radio type"
        }
    ]
}