如何从HTML页面插入mongoDB

时间:2015-05-20 10:50:39

标签: meteor

   var productDB = new Meteor.Collection('products'); //Want to insert into this DB
   var ProductParameters = nodeDB.find({"ACTIVE" : 1, "VARIENTS.ACCESS" : "PUBLIC"}, { "VARIENTS.NAME": 1, _id : 0 } ); //Taking Paramters from Another DB

    Template.dpVar.events = {   
    'click .addProduct' : function (e) {
      e.preventDefault();

      ProductParameters.forEach(function(){ **//This is my Question.How to insert into productDB the key values as {ProductParameters: Val of ProductParameters}**
        console.log(ProductParameters);
            var pvariable = {
                pvariable: tmpl.find("#ProductParameters").value
            };
        productDB.insert(pvariable);


      });

    }
  };

问题:

我已经从nodeDB的参数创建了表单。 我想将这个新表单中的数据存储在新的数据库productDB中。 我想运行一个循环,其中从nodeDB读取所有ProductParameters,并将用户在表单中插入的相应值作为新条目推送到ProductDB

编辑:

NodeDB有模板:

db.nodes.insert([
    {
        "GEOLOCATION": {
            "GEO_CODE": [], 
            "ACTIVE_GEOLOCATION": false
        }, 

        "META": {
            "CATEGORY": "levis", 
            "DESCRIPTION": "dsad", 
            "PRIVACY": "PUBLIC", 
            "TEMPLATE_NAME": "B", 

            "TEMPLATE_GROUP": "Product", 
            "KEYWORDS": [
                "sda"
            ], 
            "CREATEDBY": "", 
            "SUBCATEGORY": "Blue", 
            "PRODUCT_TEMPLATE_TYPE": "Consumable", 
            "UOM": "", 
            "TEMPLATE_SUBGROUP": ""
        }, 
        "VARIENTS": [
            {
                "COMMENT": "Demo", 
                "INDEX": 0, 
                "NAME": "Brand", 
                "IS_PARENT": false, 
                "DATATYPE": "Text", 
                "ACCESS": "PUBLIC", 
                "PARENT_VARIENT": "Parem", 
                "TYPE": "PERMANENT"
            }
        ]
    }
])

表单仅从VARIENTS

生成

ProductDB将是{key,value} = {VARIENTS.NAME,来自UI的值} 可以有多个VARIENTS,因为它只包含一个“品牌”

1 个答案:

答案 0 :(得分:1)

而不是

var ProductParameters = nodeDB.find({"ACTIVE" : 1, "VARIENTS.ACCESS" : "PUBLIC"}, { "VARIENTS.NAME": 1, _id : 0 } );

在末尾添加.fetch()

var ProductParameters = nodeDB.find({"ACTIVE" : 1, "VARIENTS.ACCESS" : "PUBLIC"}, { "VARIENTS.NAME": 1, _id : 0 } ).fetch();