How to add Bson ObjectId to JObject - mongodb

I am trying return key value by using JObject. I am getting the ObjcetId after insert the value in mongodb. I am using JObject to return the value as key value pair. By using the bellow code i assing the objectid to the key.
JObject returnId= new JObject();
dynamic id = Document["_id"].AsObjectId;
returnValue = returnId.Add("_id",id);
I am getting unhandle exception in the third line. Why i am getting this is issue and how can i solve it.
i want return the value like bellow
"_id":"12345667889"
can any one try to help me.
Thank you...

I change the bellow code
JObject returnId= new JObject();
to
BsonDocument returnId = new BsonDocument()
Now its working fine.

Related

Getting "The SqlParameter is already contained by another SqlParameterCollection." error while using SqlQuery command

I am trying to parameterize a dynamic query and run it using SqlQuery method in Entity Framework code first.
The first time I execute SqlQuery it works as expected so I am sure there is nothing wrong with query or parameters but immediately I execute the same command with the same parameters second time and I get this error
"The SqlParameter is already contained by another SqlParameterCollection."
Since I am already using ToList() method here, I have no idea what the cause could be!
Here is the simulated code.
using (var context = Common.GetDbContext())
{
var parameters = new List<SqlParameter>();
//populating parameters here...
var sqlQuery = "Select * from MyTable where UserId=#p1 and And Active=#p2";
// first time
var result = context.Database.SqlQuery<ResultType>(sqlQuery, parameters.ToArray()).ToList();
//second time
result = context.Database.SqlQuery<ResultType>(sqlQuery, parameters.ToArray()).ToList();
}
Any idea?
Hi SqlParameter is clonable. Try this:
result = context.Database.SqlQuery<ResultType>(sqlQuery, parameters.Select(x => x.Clone()).ToArray()).ToList();
See https://msdn.microsoft.com/en-us/library/vstudio/bb338957%28v=vs.100%29.aspx

split values of couch db result

I want to split the values selected from couch db in gwt according to a particular id. I tried to use the String tokenizer but couldn't found something useful. the result returned from couch db is in the following format:
{"_id":"2","_rev":"1-717f76046030a683687ace9ac8f7bdbf","course":"jbdgjbj","passwd":"rty","phone":"24125514444","clgnme":"bjfbjf","address":"jbjfbjb","name":"meenal","cpasswd":"rty","user":"2","fname":"jfbg"}
I just want to get the values and set them in textboxes.
how to do it?
try this ...
Session studentDbSession = new Session("localhost",5984);
Database studentCouchDb = studentDbSession.getDatabase("student");
System.out.println("select");
Document d = studentCouchDb.getDocument(input);
if(d.containsKey("FirstName")){
fname=d.getString("FirstName");//fname is variable
}
if(d.containsKey("LastName")){
lname=d.getString("LastName");//lname is variable
}
if(d.containsKey("Address")){
add= d.getString("Address");//add name is variable
}
finally concatenate all strings and return to client...
all=fname+" "+lname+" "+add;
return all;
This looks like JSON. You can parse it using JSONObject:
JSONObject obj = new JSONObject(yourString);
String course = obj.getString("course");

How to retrieve the value from the data attribute in node js via form submit with method post

How to get the value from the data attribute in node js via form submit.
I want to get a 2nd information from user!
My first try was this:
Clientside:
input(type="submit" ,name="responseValue" , value="yes", data="question1" )
input(type="submit" ,name="responseValue" , value="no", data="question2" )
Serverside:
//works ok
var responseValue = req.body.responseValue;
//following does not work
var questionNumber = req.body.data
Is there any solution for this without a hidden field ?
You can concatenate string in the value field and then separate it at server side.
Your client side may look like this.
input(type="submit",name="responseValue", value="yes,question1")
Then at server side you can separate the string responseValue by the index of ','.

how to parse SMValue to String array

I am just getting familiar with the StackMob server side custom code sdk and i am trying to get a relationship field and iterate through it in the form of a String array. How do i do that ? is it possble to iterate through it without parsing it into an array?
DataService ds = serviceProvider.getDataService();
List<SMCondition> query = new ArrayList<SMCondition>();
query.add(new SMEquals("product_id", new SMString(jsonObj.getString("product_id"))));
List<SMObject> results = ds.readObjects("product", query);
SMObject product= results.get(0);
//product.getValue().get("categories"); how do i get this to be a String array?
At its simplest, that would look something like this:
List<SMValue> categories = (List<SMValue>)(rawObj.getValue().get("categories").getValue());
for (SMValue smString : categories) {
SMString stringValue = (SMString)smString.getValue();
//do whatever you want with the string value here
}
Obviously there are some unchecked casts in here, so you will want to add type/null checking to the appropriate sections depending on your data & schema.

How do i set a label on an issue using the JIRA SOAP API

Is there a way to set the "Labels" field for a ticket when creating or updating a JIRA ticket using the SOAP API? A search for "label" in the WSDL reveals nothing, and when getting a ticket using the API which I know has labels set, there is no indication in the result that a label exists.
You can update the label of an existing issue using the field id 'labels'. Here is the code I'm using (C#):
public void LabelIssue(string issueKey, string label)
{
RemoteIssue issue = jiraSoapService.getIssue(token, issueKey);
List<RemoteFieldValue> actionParams = new List<RemoteFieldValue>();
RemoteFieldValue labels = new RemoteFieldValue { id = "labels", values = new string[] { label } };
actionParams.Add(labels);
jiraSoapService.updateIssue(token, issue.key, actionParams.ToArray());
}
I'm pretty sure there's no method to do this in JiraSoapService
http://docs.atlassian.com/rpc-jira-plugin/latest/com/atlassian/jira/rpc/soap/JiraSoapService.html
~Matt
Try updating custom field id 10041. I looked forever and I finally found it.
Here is sample code in python:
update_str = [{"id": "customfield_10041", "values":["my_label"]}]
ret = jira_handle.service.updateIssue(auth, key, update_str)
Hope that helps!!