I have to following code to query from dynamodb
Search search = table.Query(new QueryOperationConfig { Filter = filter, AttributesToGet = list of attributes});
I can see there is data in search by expanding its node while debugging, but could not find an easy way to get the items key and values directly.
I tried with
List<Document> documentSet = new List<Document>();
do
{
documentSet = search.GetNextSet();
foreach (var document in documentSet)
{
HttpContext.Current.Response.Write(document["columnName"]);
HttpContext.Current.Response.Write(document["columnName"]);
}
} while (!search.IsDone);
Is there any direct way to get the keys and value from Search object in json or table any in any thing?
Thanks
Given an individual Document (in your case, the document object), you can call document.ToJson() or document.ToJsonPretty() to retrieve the JSON representation of the document. This blog post provides more details.
Related
I have Added text index on my collection. I am trying to filter the data with text search with some additional filters. But It is not working well with other filters.
{$text:{$search:"test"},Type:"5"}
The above query returns all 42 entries matching the criteria from mongoDB Atlas.
But when I am doing this from c# I think I am querying it wrong. What am I missing here.
var collection = db.GetCollection<TestTbl>("TestTbl");
var filter = Builders<TestTbl>.Filter.Text(searchtext)
&Builders<TestTbl>.Filter.Eq("TypeID", TypeID);
var data = collection.Find(filter).ToList();
here data is returned null.
When I am giving text only in the filter it works fine.
{$text:{$search:"test"}}
var collection = db.GetCollection<TestTbl>("TestTbl");
var filter = Builders<TestTbl>.Filter.Text(searchtext);
var data = collection.Find(filter).ToList();
The Error was with my model it was Guid Type forgot to mention the bsontype string for the field representation
i have the following problem, i filtered the collection to get the specific document in collection which i need. The document inside it has some variable with some values. How do i grab the specific variable and its value from the specific document.
MongoClient client = new MongoClient();
var db = client.GetDatabase("myfirstdb");
var collection = db.GetCollection<PlayerInfo>("players");
var filter = Builders<PlayerInfo>.Filter.Eq("playerName", player.Name);
//find in document filter the parameter "isAdmin" and grab its value.
This is how my document looks like.
You have to use Project clause when you perform the find operation on the filter. Below code will do.
bool isAdmin = collection.Find(filter).Project(x => x.isAdmin).FirstOrDefault();
Writing programm to Parse some data from one website using AngleSharp. Unfortunately I didn't find any documentation and it makes understanding realy hard.
How can I by using QuerySelectorAll get only link? I'm getting now just all things <a ...>...</a> with Name of article.
1. Name of artucle
The method I'm using now:
var items = document.QuerySelectorAll("a").Where(item => item.ClassName != null && item.ClassName.Contains("object-title-a text-truncate"));
In the previous example I also used ClassName.Contains("object-name"), but if we deal with table cells, there are no any class. As I understand to parse right element maybee I must use some info about parent also. So here is the question, how can I get this '4' value from tabble cell?
....<th class="strong">Room</th>
<td>4</td>....
Regarding your first question.
Here is an example that you can extract the link address.
This a Link of another Stackoveflow post that is related.
var source = #"<a href='http://kinnisvaraportaal-kv-ee.postimees.ee/muua-odra-tanaval-kesklinnas-valmiv-suur-ja-avar-k-2904668.html?nr=1&search_key=69ec78d9b1758eb34c58cf8088c96d10' class='object-title-a text-truncate'>1. Name of artucle</a>";
var parser = new HtmlParser();
var doc = parser.Parse(source);
var selector = "a";
var menuItems = doc.QuerySelectorAll(selector).OfType<IHtmlAnchorElement>();
foreach (var i in menuItems)
{
Console.WriteLine(i.Href);
}
For your Second question, you can check the example on the documention, here is the Link and below is the code sample:
// Setup the configuration to support document loading
var config = Configuration.Default.WithDefaultLoader();
// Load the names of all The Big Bang Theory episodes from Wikipedia
var address = "https://en.wikipedia.org/wiki/List_of_The_Big_Bang_Theory_episodes";
// Asynchronously get the document in a new context using the configuration
var document = await BrowsingContext.New(config).OpenAsync(address);
// This CSS selector gets the desired content
var cellSelector = "tr.vevent td:nth-child(3)";
// Perform the query to get all cells with the content
var cells = document.QuerySelectorAll(cellSelector);
// We are only interested in the text - select it with LINQ
var titles = cells.Select(m => m.TextContent);
I know how I can output my graph database to a file (like a GraphML file), but I'd rather iterate through the nodes and have them as C# objects because I need to use them elsewhere.
Something like this:
var it = graph.GetNodeIterator();
while (it.HasNext()) {
var node = new MyNodeObject();
//get attributes or whatever
nodeList.Add(node);
}
//nodeList now contains all nodes in a List
I can't find a convenient way to do this and the Dex documentation isn't very helpful. Clearly Dex has some way of doing this because I can easily export to GraphML, but I don't want to export to GraphML and then parse the GraphML into C# objects.
Here is how I do it, not sure if it's the best way though:
//find the type(s) youre looking for based on how you assigned
//them in the first place. you may already know.
var typeIt = graph.FindTypes().Iterator();
while (typeIt.HasNext()) {
//find your types if you dont know
}
//select the types you want. lets say all of your nodes have one of two types,
//which map to attributes 4 and 3.
var select = graph.Select(4);
//union them
select.Union(graph.Select(3));
//start to iterate
var it = select.Iterator();
while (it.HasNext()) {
var next = it.Next();
//map to your own objects using next
}
Basically I have a single element inside of an xml file where I store settings for my application. This element mirrors a class that I have built. What I'm trying to do using LINQ, is select that single element, and then store the values stored inside of that element into an instance of my class in a single statement.
Right now I'm selecting the element seperately and then storing the values from that element into the different properties. Of course this turns into about six seperate statements. Is it possible to do this in a single statement?
It will be better if you can show your XML but you can get general idea from code below
XDocument doc = //load xml document here
var instance = from item in doc.Descendants("ElementName")
select new YourClass()
{
//fill the properties using item
};
You can use LINQ to XML, e.g.
var document = XDocument.Load("myxml.xml");
document.Element("rootElement").Element("myElement").Select(e =>
new MySettingsClass
{
MyProperty = e.Attribute("myattribute").Value,
MyOtherProperty = e.Attribute("myotherattribute").Value
});
See http://msdn.microsoft.com/en-us/library/bb387098.aspx for more details.