CloudJedi
2015-03-05 00:05:32 UTC
I have the following structure in hash table in the form of nested
key/value pairs. Let's say I have a collection in MongoDB named structure.
How do I insert only the key/value pairs inside FIELDS: { key: 'value',
key: 'value' } into this structure collection?
var input 4 = { { OBJ_TYPE: 'Paris',
NAME: 'Paris.Name,
FIELDS:
{ UNAME: 'STRING', // key is NAME, value is STRING
DESC: 'STRING' // key is DESC, value is STRING
}
}
{ OBJ_TYPE: 'London',
NAME: 'London.Name,
FIELDS:
{ UNAME: 'STRING',
DESC: 'STRING'
}}
{ OBJ_TYPE: 'X',
NAME: 'X.XName,
FIELDS:
{ UNAME: 'STRING',
DESC: 'STRING'
}
}
}
var test = Message.init(input4);
var hashTable = test.hash_table;
if(hashTable["OBJECT_TYPE"] == "FEED"){
for(var key in hashTable){
if(key == "FIELDS"){
var keyHashTable = hashTable[key];
for(var column in keyHashTable){
var key;
var columns = new Array();
if(column == "NAME"){
key = column;
print("key"+key);
}else{
print("column"+column);
}
structure.update(
{key:null},
*{$set:{/*some dynamic variable or logic here */ }},*
{upsert:true},
function(err,data){
if (err){
console.log(err);
}else{
//console.log("Successfully upserted");
}
});
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/8427570a-8513-44fb-a456-d6b129242c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
key/value pairs. Let's say I have a collection in MongoDB named structure.
How do I insert only the key/value pairs inside FIELDS: { key: 'value',
key: 'value' } into this structure collection?
var input 4 = { { OBJ_TYPE: 'Paris',
NAME: 'Paris.Name,
FIELDS:
{ UNAME: 'STRING', // key is NAME, value is STRING
DESC: 'STRING' // key is DESC, value is STRING
}
}
{ OBJ_TYPE: 'London',
NAME: 'London.Name,
FIELDS:
{ UNAME: 'STRING',
DESC: 'STRING'
}}
{ OBJ_TYPE: 'X',
NAME: 'X.XName,
FIELDS:
{ UNAME: 'STRING',
DESC: 'STRING'
}
}
}
var test = Message.init(input4);
var hashTable = test.hash_table;
if(hashTable["OBJECT_TYPE"] == "FEED"){
for(var key in hashTable){
if(key == "FIELDS"){
var keyHashTable = hashTable[key];
for(var column in keyHashTable){
var key;
var columns = new Array();
if(column == "NAME"){
key = column;
print("key"+key);
}else{
print("column"+column);
}
structure.update(
{key:null},
*{$set:{/*some dynamic variable or logic here */ }},*
{upsert:true},
function(err,data){
if (err){
console.log(err);
}else{
//console.log("Successfully upserted");
}
});
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/8427570a-8513-44fb-a456-d6b129242c5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.