Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am newbie to MongoDb.I am having a database and in the collection I am finding a json tag and under that list of details are listed in a key value pair. How to access the json array of elements using c# .Net ?

The json structure is similar like this
{
"_id" : "AA104eM_8_en-ca",
"documentId" : "AA104eM",
"version" : 8,
"locale" : "en-ca",
"json" : {
"type" : "image",
"_id" : "AA104eM",
"_links" : {
"parent" : [
{
"href" : "cms/api/amp/section/AAimw"
}
],
"feed" : [
{
"href" : "cms/api/amp/feed/AA28Wv"
}
],
"provider" : [
{
"href" : "cms/api/amp/provider/AA1VFq"
}
],
"self" : [
{
"href" : "cms/api/amp/image/AA104eM"
}
]
},
"_name" : "Conservatve MP Eve Adams is pictured November 28, 2013 in Ottawa. THE CANADIAN PRESS/Adrian Wyld",
"_lastEditedDateTime" : "2015-07-22T10:03:26Z",
"_lastPublishedDateTime" : "2015-07-22T10:03:27.179Z",
"_locale" : "en-ca",
"keywords" : [],
"facets" : [
{
"key" : "jobEnvironment",
"values" : [
"SDP-Prod-Co3"
]
},
{
"key" : "jobInstanceName",
"values" : [
"2014-05-24_03_19_29.059-AMP-Generic_News-"
]
},
{
"key" : "feedUrl",
"values" : [
"example.xml"
]
}
],
"_expirationDateTime" : "2114-06-24T00:00:00Z",
"title" : "Conservatve MP Eve Adams is pictured November 28, 2013 in Ottawa. THE CANADIAN PRESS/Adrian Wyld",
"altText" : "Conservatve is pictured November 28, 2013 in Ottawa. THE CANADIAN PRESS/Adrian Wyld",
"caption" : "Conservatve is pictured November 28, 2013 in Ottawa. THE CANADIAN PRESS/Adrian Wyld",
"attribution" : "Provided by Press",
"width" : 650,
"height" : 482,
"focalRegion" : {
"x1" : 268,
"y1" : 114,
"x2" : 398,
"y2" : 244
},
"href" : "http://com.akamaized.net/tenant/amp/entityid/AA104eM.img",
"crops" : [],
"fileSize" : 0,
"subscriptionType" : "Free",
"copyright" : "Provided by Press",
"_processingStatus" : {
"quality" : "Complete",
"optimization" : "Complete",
"face2d" : "Complete",
"messages" : []
},
"sourceHref" : "http://cnet:88/cosmos/AMP.prod/local/Working/SDP-Prod-Ch1/AMP/2014-05-24_03_19_29.059-AMP-Generic_News-/RawImages.dat#_separator_#ftp://ftp2.cp.org/downloads/online/MicrosoftMSN5/National/CPW1203189029_high.jpg",
"excludedExperiences" : [],
"excludedVerticals" : [],
"_systemTags" : [],
"_lastPublishedSequence" : 7
}
}

What I have tried:

I have installed C# .Net driver and able to connect with MongoDb programmatically.


The code used for connectivity to db from c# application

var conString = "mongodb://localhost:27017";
var Client = new MongoClient(conString);
var DB = Client.GetDatabase("test");
var collection = DB.GetCollection<bsondocument>("test");

How to fetch the details namely like the one in href key? Do i need to install any other dlls to access the details in the json tag(ref above mentioned example)?any coding example for this case would be of great help !!
Posted
Updated 5-May-16 1:58am
v3

This looks like a reasonable starting point for you:
Getting Started with MongoDB (C# Edition)[^]

Read the documentation, try the examples and then come back with a more specific question where you show some code and where you have a problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900