garima
garima

Reputation: 5244

How to insert into mongoDB from HTML page

   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);


      });

    }
  };

Problem:

I have created form from the Parameters of nodeDB. I want to store the data from this new form in a new DB productDB. I want to run a loop where all the ProductParameters are read from nodeDB and their corresponding values inserted in form by user are pushed into ProductDB as new Entry.

EDIT:

NodeDB has Templates:

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"
            }
        ]
    }
])

The form is generated only from the VARIENTS

The ProductDB would be {key,value} ={VARIENTS.NAME,value from UI} There can be multiple VARIENTS as this contains only one "Brand"

Upvotes: 0

Views: 102

Answers (1)

Gerwin Brunner
Gerwin Brunner

Reputation: 196

instead of

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

add .fetch() at the end

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

Upvotes: 1

Related Questions