0
   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"

4
  • Can you show us some sample documents from both the productsDB and nodeDB? Commented May 20, 2015 at 11:33
  • ok.Let me edit..1min Commented May 20, 2015 at 11:34
  • ProductParameters is cursor, at the end of find() add .fetch() which will return normal array Commented May 20, 2015 at 16:20
  • ok, can you share how to use it Commented May 20, 2015 at 17:04

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.