Hii I am trying to save my HTML form data in the database. I create a JSON file for Dynamic fields and I bind it but there is some problem that's why data is not save. When I save the data, the same data is saved as it is in the JSON file as if I entered some string value in the input field, it is not saved but the original string is the same.
<div>
<p *ngFor="let item of doclist">
{{ item.label }}
<ejs-checkbox [(ngModel)]="item.value" id="item.value" name="item.value">
{{ item.value }}
</ejs-checkbox>
<ejs-textbox *ngIf="item.value == true && !false"[(ngModel)]="item.comment"
name="item.comment">
{{ item.comment }}
</ejs-textbox>
</p>
</div>
public doclist : {}[] = db;
public doc = JSON.stringify(this.doclist);
this.salesToOpsHand.documentList = this.doc;
`// documentList in that i have to save my all json string value so i write here doc values == documentList`
this is my db.json file
[
{
"name" : "IsSpecifications",
"label" : "isSpecifications() ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "IsDrawSchedule",
"label" : "Drawings/Schedules ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "TqRfi",
"label" : "TQ’s / RFI’s ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "InsEnqReqQouInfor",
"label" : "Install Enquiry / request to quote information ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "PanEnqReqQouInfor",
"label" : "Panel Enquiry / request to quote information ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "PanSubContQuot",
"label" : "Panel Sub Contractor Quotation ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "MccSchedule",
"label" : "MCC Schedules ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "ScPackQuot",
"label" : "Other S/C Package Quotations ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "OthrdPartyQuot",
"label" : "Other 3rd Party Quotations ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "EquipSchedule",
"label" : "Equipment Schedules ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "PointSchedul",
"label" : "Points Schedules ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "ValveSchedul",
"label" : "Valve Schedules ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "IdentRiskOpport",
"label" : "Identifed Risks and Opportunities (INCL. VALUE ENGINEERING) ",
"value" : false,
"type" : "checkbox",
"comment" : ""
},
{
"name" : "InstSubContQuot",
"label" : "Install Sub Contractor Quotation ",
"value" : false,
"type" : "checkbox",
"comment" : ""
}
]
`if someone knows where is am doing a mistake please help me
here I try angular and JSON file and save the value in form of a string in the server side`
Related
I have the following data:-
**{
"_id" : ObjectId("5bf8048768d1e82d8bb4a477"),
"customer_code" : "c100003",
"vm_info" : [
{
"instanceId" : "i-0495d75742b839858",
"tags" : [
{
"Key" : "SIDs",
"Value" : "NWS"
},
{
"Key" : "OSTYPE",
"Value" : "WINDOWS"
},
{
"Key" : "BACKUP_SERVER_LOCATION",
"Value" : ""
},
{
"Key" : "OS_VERSION",
"Value" : "10"
}
]
},
{
"instanceId" : "i-017488cffca28cd70",
"tags" : [
{
"Key" : "OS_VERSION",
"Value" : "10"
},
{
"Key" : "BACKUP_SERVER_LOCATION",
"Value" : ""
},
{
"Key" : "OSTYPE",
"Value" : "WINDOWS"
},
{
"Key" : "SIDs",
"Value" : "NWS"
}
]
},
{
"instanceId" : "i-09d5db81657fe35d8",
"tags" : [
{
"Key" : "SIDs",
"Value" : "NWS"
},
{
"Key" : "BACKUP_SERVER_LOCATION",
"Value" : ""
},
{
"Key" : "OSTYPE",
"Value" : "WINDOWS"
},
{
"Key" : "OS_VERSION",
"Value" : "10"
}
]
}
]
}**
Now i want to update the value of "OS_VERSION" to "12" instead of "10". After updating it should look like this:-
**{
"_id" : ObjectId("5bf8048768d1e82d8bb4a477"),
"customer_code" : "c100003",
"vm_info" : [
{
"instanceId" : "i-0495d75742b839858",
"tags" : [
{
"Key" : "SIDs",
"Value" : "NWS"
},
{
"Key" : "OSTYPE",
"Value" : "WINDOWS"
},
{
"Key" : "BACKUP_SERVER_LOCATION",
"Value" : ""
},
{
"Key" : "OS_VERSION",
"Value" : "12"
}
]
},
{
"instanceId" : "i-017488cffca28cd70",
"tags" : [
{
"Key" : "OS_VERSION",
"Value" : "10"
},
{
"Key" : "BACKUP_SERVER_LOCATION",
"Value" : ""
},
{
"Key" : "OSTYPE",
"Value" : "WINDOWS"
},
{
"Key" : "SIDs",
"Value" : "NWS"
}
]
},
{
"instanceId" : "i-09d5db81657fe35d8",
"tags" : [
{
"Key" : "SIDs",
"Value" : "NWS"
},
{
"Key" : "BACKUP_SERVER_LOCATION",
"Value" : ""
},
{
"Key" : "OSTYPE",
"Value" : "WINDOWS"
},
{
"Key" : "OS_VERSION",
"Value" : "10"
}
]
}
]
}**
When i use Update operator with "$addToSet" a new Key-Value pair is added instead of updating the existing data like this:
**{
"_id" : ObjectId("5bf8048768d1e82d8bb4a477"),
"customer_code" : "c100003",
"vm_info" : [
{
"instanceId" : "i-0495d75742b839858",
"tags" : [
{
"Key" : "SIDs",
"Value" : "NWS"
},
{
"Key" : "OSTYPE",
"Value" : "WINDOWS"
},
{
"Key" : "BACKUP_SERVER_LOCATION",
"Value" : ""
},
{
"Key" : "OS_VERSION",
"Value" : "10"
},
{
"Key" : "OS_VERSION",
"Value" : "12"
}
]
}
]
}** I don't want it to be added as a new element ,instead it should just update the existing element.
How can i achieve the desired result. Can someone help on this.
first remove that key-value pair and and insert new one.
I'm able to do
db.getCollection('comps').find({"stats.cat3.detail.name" : "Friendlyness"})`
This shows the proper docs the have a name of "Friendlyness" in the detail array.
I wanted to change "Friendlyness" to "friendliness"
I tried :
db.getCollection('comps').update(
{"stats.cat3.detail.name" : "Friendlyness"},
{$set : {"stats.cat3.detail.name" : "Friendliness"} }
)
and got errors like
" cannot use the part (stats of stats.cat3.detail.name) to traverse the element ({stats: [ { cat3: ...."
I tried putting in position operators "$" all over the update object property. but still get errors.
sample data:
{
"_id" : ObjectId("58d94c441eb9e52454932db6"),
"desc" : "Manufacturer of a wide range of consumer electronics products including audio, video, communications, and computer systems.",
"source" : "alexa",
"category" : "Consumer Electronics",
"name" : "comp1.com",
"__v" : 0,
"stats" : [
{
"cat1" : {
"detail" : [
{
"value" : [
{
"data" : 1,
"name" : "quick service"
}
],
"name" : "Time on hold"
},
{
"value" : [
{
"data" : 1,
"name" : "some words but strong accent"
},
{
"data" : 1,
"name" : "EZ to understand"
}
],
"name" : "Language fluency"
},
{
"value" : [
{
"data" : 1,
"name" : "Yes"
}
],
"name" : "Human answered"
},
{
"value" : [
{
"data" : 2,
"name" : "Like a hot potato"
},
{
"data" : 1,
"name" : "1 or 2 times"
}
],
"name" : "Transfered alot"
},
{
"value" : [
{
"data" : 3,
"name" : "ok time"
},
{
"data" : 1,
"name" : "quick service"
},
{
"data" : 1,
"name" : "short time"
}
],
"name" : "Time on Hold"
},
{
"value" : [
{
"data" : 1,
"name" : "some word but strong accent"
},
{
"data" : 2,
"name" : "EZ to understand"
}
],
"name" : "Language Fluency"
},
{
"value" : [
{
"data" : 2,
"name" : "Yes"
}
],
"name" : "Human Answered"
}
],
"average" : 81
},
"cat2" : {
"detail" : [
{
"value" : [
{
"data" : 1,
"name" : "It was ok"
},
{
"data" : 1,
"name" : "Not EZ at all"
},
{
"data" : 7,
"name" : "there were hidden gimicks"
},
{
"data" : 2,
"name" : "It was OK"
},
{
"data" : 1,
"name" : "Found Quickly"
}
],
"name" : "Easy to find desired product"
},
{
"value" : [
{
"data" : 1,
"name" : "Easy to understand"
},
{
"data" : 1,
"name" : "Eventually understood"
}
],
"name" : "Clear information about the product"
},
{
"value" : [
{
"data" : 2,
"name" : "none"
},
{
"data" : 3,
"name" : "There was but won't complain"
},
{
"data" : 1,
"name" : "Very Bad"
}
],
"name" : "Annoying popups"
},
{
"value" : [
{
"data" : 4,
"name" : "Eventually Understood"
},
{
"data" : 1,
"name" : "EZ to understand"
}
],
"name" : "Clear data about the product"
}
],
"average" : 71
},
"cat3" : {
"detail" : [
{
"value" : [
{
"data" : 1,
"name" : "Very quick"
}
],
"name" : "Prompteness"
},
{
"value" : [
{
"data" : 3,
"name" : "We're cool"
},
{
"data" : 4,
"name" : "They didn't like me"
}
],
"name" : "Friendlyness"
},
{
"value" : [
{
"data" : 3,
"name" : "Very Confusing"
},
{
"data" : 2,
"name" : "Still a little confused"
},
{
"data" : 3,
"name" : "Enlightened"
}
],
"name" : "Knowledge"
},
{
"value" : [
{
"data" : 3,
"name" : "On hold too many times"
}
],
"name" : "Promptness"
}
],
"average" : 69
}
}
]
}
I need to convert a collection with nested documents to a model tree structure with parent references. So this is how my structure looks like:
{
"_id" : "sdaGREsfRdfGdFdwG",
"docTitle" : "Document 1",
"group" : [
{
"id" : "cdPhkTpMXi8z6TqMT"
"title" : "title 1",
"data" : [
{
"id" : "Nkspf5kKfPo3axeJA",
"some" : "data",
"other" : "things",
"and" : "so on",
},
{
"id" : "Ca8ncFgq83RoeD8he",
"some" : "data",
"other" : "things",
"and" : "so on",
},
{
"id" : "vyjgkuNXRN9KkCd5o",
"some" : "data",
"other" : "things",
"and" : "so on",
}
],
},
{
"id" : "TuibXPe5qMvqdMW6q"
"title" : "title 2",
"data" : [
{
"id" : "f5L5zsSNRSQKWoAXL",
"some" : "data",
"other" : "things",
"and" : "so on",
}
],
}
]
}
As you can see, there is a group array, which has also a data array. Now I need a main document like this:
{
"_id" : "sdaGREsfRdfGdFdwG",
"docTitle" : "Document 1"
}
And the next child elements, which would be:
{
"id" : "cdPhkTpMXi8z6TqMT"
"title" : "title 1",
"type" : "group",
"parent" : "sdaGREsfRdfGdFdwG"
},
{
"id" : "TuibXPe5qMvqdMW6q"
"title" : "title 2",
"type" : "group",
"parent" : "sdaGREsfRdfGdFdwG"
}
At least the data elements, which are children of the group-elements:
{
"id" : "Nkspf5kKfPo3axeJA",
"some" : "data",
"other" : "things",
"and" : "so on",
"type" : "element",
"parent" : "cdPhkTpMXi8z6TqMT"
},
{
"id" : "Ca8ncFgq83RoeD8he",
"some" : "data",
"other" : "things",
"and" : "so on",
"type" : "element",
"parent" : "cdPhkTpMXi8z6TqMT"
},
{
"id" : "vyjgkuNXRN9KkCd5o",
"some" : "data",
"other" : "things",
"and" : "so on",
"type" : "element",
"parent" : "cdPhkTpMXi8z6TqMT"
},
{
"id" : "f5L5zsSNRSQKWoAXL",
"some" : "data",
"other" : "things",
"and" : "so on",
"type" : "element",
"parent" : "TuibXPe5qMvqdMW6q"
}
So my attempt would be something like this:
Collection.find({}).forEach(function(doc) { // get all documents
var docID = doc._id;
doc.group.forEach(function(group) { // get all groups
var parent = group.id;
group.type = "group";
group.parent = docID;
group.data.forEach(function(element) { // get all elements
element.type ="element";
element.parent = parent;
});
});
});
1) I don't know how to do that in a better way
2) And I don't know how to save the result back to the collection
Fot the groups:
db.myCol.aggregate([{$unwind:"$group"},
{$project:{_id:"$group.id", some:"$group.some",
parent:"$_id", type:{$literal:"group"}}}])
For the Elements:
db.myCol.aggregate([{$unwind:"$group"},
{$unwind:"$group.data"},
{$project:{_id:"$group.data.id", some:"$group.data.some",
parent:"$group.id", type:{$literal:"element"}}}])
And to your second question: You can add an $out step to the aggregation pipeline at the end. For example: {$out:"outputCol"}
I am using mongoose and node and I am trying to paginate data from sub-documents. I am able to limit subdocuments, but not skip them.
The versions I am using are:
Mongo 3.0.0
Node 0.10.33
Mongoose 3.9.7
The Data
[{
"name" : "Ranger Table",
"_id" : ObjectId("550234d3d06039d507d238d8"),
"body" : [
{
"name" : "Jason",
"colour" : "Red",
"animal" : "T-rex",
"_id" : ObjectId("550234d3d06039d507d238de")
},
{
"name" : "Billy",
"colour" : "Blue",
"animal" : "Triceratops",
"_id" : ObjectId("550234d3d06039d507d238dd")
},
{
"name" : "Zach",
"colour" : "Black",
"animal" : "Mastadon",
"_id" : ObjectId("550234d3d06039d507d238dc")
},
{
"name" : "Tommy",
"colour" : "Green",
"animal" : "Dragon"
"_id" : ObjectId("550234d3d06039d507d238d9")
}
]
},{
"name" : "Bot Table",
"_id" : ObjectId("5502d205184cd74033f64e6b"),
"body" : [
{
"name" : "Optimus",
"team" : "Autobots",
"class" : "Leader",
"_id" : ObjectId("550234d3d06039d507d238d9")
},
{
"name" : "Bumblebee",
"team" : "Autobots",
"class" : "Scout",
"_id" : ObjectId("550234d3d06039d507d238da")
},
{
"name" : "Astrotrain",
"team" : "Decepticons",
"class" : "Transport",
"_id" : ObjectId("550234d3d06039d507d238db")
}
]
}]
The Code
var BodySchema = new Schema({random: String},{strict:false});
var FeedSchema = new Schema({
name: String,
body:[BodySchema]
});
var feed = mongoose.model('Feed', FeedSchema);
feed.find({_id:'550234d3d06039d507d238d8'})
.populate({
"path":"body",
"options":{
limit:2, //This works fine
skip:2 //This doesn't work
}
})
.exec(function(err, result){
if(err){return(res.send(500, err))}
res.send(result);
});
The Result
The above code DOES limit the number of "body" sub-documents to 2, but doesn't skip any.
The code above returns this:
{
"name" : "Ranger Table",
"_id" : ObjectId("550234d3d06039d507d238d8"),
"body" : [
{
"name" : "Jason",
"colour" : "Red",
"animal" : "T-rex",
"_id" : ObjectId("550234d3d06039d507d238de")
},
{
"name" : "Billy",
"colour" : "Blue",
"animal" : "Triceratops",
"_id" : ObjectId("550234d3d06039d507d238dd")
}
]
}
But it should return this:
{
"name" : "Ranger Table",
"_id" : ObjectId("550234d3d06039d507d238d8"),
"body" : [
{
"name" : "Zach",
"colour" : "Black",
"animal" : "Mastadon",
"_id" : ObjectId("550234d3d06039d507d238dc")
},
{
"name" : "Tommy",
"colour" : "Green",
"animal" : "Dragon"
"_id" : ObjectId("550234d3d06039d507d238d9")
}
]
}
The solution that I found was to use aggregate and specify the name of the subdocument with $unwind.
http://docs.mongodb.org/manual/reference/operator/aggregation/
feed.aggregate([
{'$match':{_id:id('550234d3d06039d507d238d8')}},
{'$unwind':'$body'},
{'$skip':2},
{'$limit':2},
], function(err, result){
if(err){return(res.send(500, err))}
res.send(result);
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
{
"action" : "get",
"application" : "2c5ca3b0-be74-11e4-8ff3-f7af49a474ef",
"params" : {
"ql" : [ "select * where username='pqr'" ]
},
"path" : "/logs",
"uri" : "https://api.usergrid.com/serv-d/demo1/logs",
"entities" : [ {
"uuid" : "97b0fd0a-be74-11e4-9324-b3bd8af7859e",
"type" : "log",
"created" : 1425036869840,
"modified" : 1425036869840,
"metadata" : {
"path" : "/logs/97b0fd0a-be74-11e4-9324-b3bd8af7859e"
},
"password" : "pqr",
"username" : "pqr"
}],
"timestamp" : 1425359738746,
"duration" : 15,
"organization" : "serv-d",
"applicationName" : "demo1",
"count" : 1
}
This is the server side response to my app and I want to get the user name and password values only.
Use JSON.parse() to parse the JSON response into a Javascript object. Then you can access the properties.
var obj = JSON.parse(response);
The username and password are in an array that's in the entities property, so you can access them as:
var username = obj.entities[0].username;
var password = obj.entities[0].password;
Get the data in a variable, say in variable data.
var data = {
"action" : "get",
"application" : "2c5ca3b0-be74-11e4-8ff3-f7af49a474ef",
"params" : {
"ql" : [ "select * where username='pqr'" ]
},
"path" : "/logs",
"uri" : "https://api.usergrid.com/serv-d/demo1/logs",
"entities" : [ {
"uuid" : "97b0fd0a-be74-11e4-9324-b3bd8af7859e",
"type" : "log",
"created" : 1425036869840,
"modified" : 1425036869840,
"metadata" : {
"path" : "/logs/97b0fd0a-be74-11e4-9324-b3bd8af7859e"
},
"password" : "pqr",
"username" : "pqr"
}],
"timestamp" : 1425359738746,
"duration" : 15,
"organization" : "serv-d",
"applicationName" : "demo1",
"count" : 1
};
//logging username and password fields
console.log(data.entities[0].username, data.entities[0].password);
JSON behaves like key value pair kind of collection. Assign this Json to Javascript variable and then you can get the values of JSON with respective key like
var myJson =
{
"action" : "get", "application" : "2c5ca3b0-be74-11e4-8ff3-
f7af49a474ef", "params" : { "ql" : [ "select * where
username='pqr'" ] }, "path" : "/logs", "uri" :
"https://api.usergrid.com/serv-d/demo1/logs", "entities" : [
{ "uuid" : "97b0fd0a-be74-11e4-9324-b3bd8af7859e", "type" :
"log", "created" : 1425036869840, "modified" :
1425036869840, "metadata" :
{ "path" : "/logs/97b0fd0a-be74-11e4-9324-b3bd8af7859e"
}, "pas sword" : "pqr", "username" : "pqr"
}], "timestamp" : 1425359738746, "duration" : 15,
"organization" : "serv-d", "applicationName" : "demo1",
"count" : 1 };
var action = myJSON.action;
var uri = myJSON.uri; and so on..
Assuming you store it as "obj", then you can do obj.entities[0].username (and likewise for password.
Assuming you are referring it as data, You can use data.entities[0].username to access username.
var data = {
"action": "get",
"application": "2c5ca3b0-be74-11e4-8ff3-f7af49a474ef",
"params": {
"ql": [
"select * where username='pqr'"
]
},
"path": "/logs",
"uri": "https://api.usergrid.com/serv-d/demo1/logs",
"entities": [
{
"uuid": "97b0fd0a-be74-11e4-9324-b3bd8af7859e",
"type": "log",
"created": 1425036869840,
"modified": 1425036869840,
"metadata": {
"path": "/logs/97b0fd0a-be74-11e4-9324-b3bd8af7859e"
},
"password": "pqr",
"username": "pqr"
}
],
"timestamp": 1425359738746,
"duration": 15,
"organization": "serv-d",
"applicationName": "demo1",
"count": 1
};
alert(data.entities[0].username)
alert(data.entities[0].password)
var yourData = {
"action" : "get",
"application" : "2c5ca3b0-be74-11e4-8ff3-f7af49a474ef",
"params" : {
"ql" : [ "select * where username='pqr'" ]
},
"path" : "/logs",
"uri" : "https://api.usergrid.com/serv-d/demo1/logs",
"entities" : [ {
"uuid" : "97b0fd0a-be74-11e4-9324-b3bd8af7859e",
"type" : "log",
"created" : 1425036869840,
"modified" : 1425036869840,
"metadata" : {
"path" : "/logs/97b0fd0a-be74-11e4-9324-b3bd8af7859e"
},
"password" : "pqr",
"username" : "pqr"
}],
"timestamp" : 1425359738746,
"duration" : 15,
"organization" : "serv-d",
"applicationName" : "demo1",
"count" : 1
}
Because username and password is data of entities- that is an array of one element member
you may access the username data
var username = yourData.entities[0].username
Similarly for password