I want to use the RavenDB. I want to do a system for administration news with comments.
I expect perhaps 500 comments in one news.
What is correct structure for news with comments? Whats type of cases can I use the following structures of the documents?
1.) Comments are in the news object
{
"News": [
{
"NewsId": "1",
"Title": "Name",
"Content": "Text",
"Comments": [
{
"CommentId": "1",
"Comment": "Text"
},
{
"CommentId": "2",
"Comment": "Text"
}
]
}
]
}
2.) News and comments are into separate objects:
News:
{
"News": [
{
"NewsId": "1",
"Title": "Name",
"Content": "Text",
"CommentId": "1"
}
]
}
Comments:
{
"Comments": [
{
"CommentId": "1",
"Comment": "Text"
},
{
"CommentId": "2",
"Comment": "Text"
}
]
}
Usually you will want to put this on separate objects, if you are accessing the news item without the comments.
Related
Version 4 of the Amazon product advertising api let you use the AlternateVersions response group to get related products, which for books let you get all the different formats of a book listing (hardcover, paperback, mass market, etc.)
Version 5 of the API does not have AlternateVersions for some reason. Is there any way to get the different versions of a book in PAAPI5?
I'm having the same issue. In my case I need just hardcover and kindle version of a book.
GetVariations (successor of AlternateVersions) is for some reason not working for books and just returns no result back.
The only possible way that I'm aware of is to do two API request (SearchItems) including the specific search index Books for books and KindleStore for kindle files. Not specifying the search index normally returns you just the hardcopy of the Books search index.
To differentiate between books and kindle version check the ItemInfo.Classifications.ProductGroup.DisplayValue or ItemInfo.Classifications.Binding.DisplayValue
For some unknown reason (at least to me) the API is returning only a subset of results when not specifying the search index (in the below example the kindle one)
Example
In the following example I looking for the hardcopy or kindle of the book with ISBN 9780262043649 by doing a SearchItem request.
a) Hardcopy with given search index
Payload
{
"Keywords": "9780262043649",
"Resources": [
"ItemInfo.Classifications",
"ItemInfo.Title"
],
"SearchIndex": "Books",
"PartnerTag": "*******",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
Response
{
"SearchResult": {
"Items": [
{
"ASIN": "0262043645",
"DetailPageURL": "https://www.amazon.com/dp/0262043645?tag=getabstractcom&linkCode=osi&th=1&psc=1",
"ItemInfo": {
"Classifications": {
"Binding": {
"DisplayValue": "Hardcover",
"Label": "Binding",
"Locale": "en_US"
},
"ProductGroup": {
"DisplayValue": "Book",
"Label": "ProductGroup",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "Novacene: The Coming Age of Hyperintelligence (The MIT Press)",
"Label": "Title",
"Locale": "en_US"
}
}
}
],
"SearchURL": "https://www.amazon.com/s?k=9780262043649&i=stripbooks&rh=p_n_availability%3A-1&tag=getabstractcom&linkCode=osi",
"TotalResultCount": 1
}
}
b) Kindle with given search index
Payload
{
"Keywords": "9780262043649",
"Resources": [
"ItemInfo.Classifications",
"ItemInfo.Title"
],
"SearchIndex": "KindleStore",
"PartnerTag": "******",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
Response
{
"SearchResult": {
"Items": [
{
"ASIN": "B08BT4MM18",
"DetailPageURL": "https://www.amazon.com/dp/B08BT4MM18?tag=getabstractcom&linkCode=osi&th=1&psc=1",
"ItemInfo": {
"Classifications": {
"Binding": {
"DisplayValue": "Kindle Edition",
"Label": "Binding",
"Locale": "en_US"
},
"ProductGroup": {
"DisplayValue": "Digital Ebook Purchas",
"Label": "ProductGroup",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "Novacene: The Coming Age of Hyperintelligence",
"Label": "Title",
"Locale": "en_US"
}
}
}
],
"SearchURL": "https://www.amazon.com/s?k=9780262043649&i=digital-text&rh=p_n_availability%3A-1&tag=getabstractcom&linkCode=osi",
"TotalResultCount": 1
}
}
c) No specific search index
Payload
{
"Keywords": "9780262043649",
"Resources": [
"ItemInfo.Classifications",
"ItemInfo.Title"
],
"PartnerTag": "*******",
"PartnerType": "Associates",
"Marketplace": "www.amazon.com",
"Operation": "SearchItems"
}
Response
{
"SearchResult": {
"Items": [
{
"ASIN": "B08BT4MM18",
"DetailPageURL": "https://www.amazon.com/dp/B08BT4MM18?tag=getabstractcom&linkCode=osi&th=1&psc=1",
"ItemInfo": {
"Classifications": {
"Binding": {
"DisplayValue": "Kindle Edition",
"Label": "Binding",
"Locale": "en_US"
},
"ProductGroup": {
"DisplayValue": "Digital Ebook Purchas",
"Label": "ProductGroup",
"Locale": "en_US"
}
},
"Title": {
"DisplayValue": "Novacene: The Coming Age of Hyperintelligence",
"Label": "Title",
"Locale": "en_US"
}
}
}
],
"SearchURL": "https://www.amazon.com/s?k=9780262043649&rh=p_n_availability%3A-1&tag=getabstractcom&linkCode=osi",
"TotalResultCount": 1
}
}
You can try those examples in the API's scratchpad.
More information about the search index of the product advertising API is available on the official documentation here
{
"data": [
{
"_id": 555,
"username": "jackson",
"status": "i am coding",
"comments": [
{
"user": "bob",
"comment": "bob me "
},
{
"user": "daniel",
"comment": "bob the builder"
},
{
"user": "jesus",
"comment": "bob the builder"
},
{
"user": "hunter",
"comment": "bob the builder"
},
{
"user": "jeo",
"comment": "bob the builder"
},
{
"user": "jill",
"comment": "bob the builder"
}
]
}
]
}
so i want to get the result with _id :555 and user:bob i tried with below code but i cant make it work it returns empty array
app.get('/all',function(req , res){
db.facebook.find({_id:555},{comments:[{user:"bob"}]},function(err,docs){res.send(docs,{data:docs});});
} );
i want the result to be like this listed below with the comment with user:bob
{
"_id": 555,
"username": "jackson",
"status": "i am coding",
"comments": [
{
"user": "bob",
"comment": "bob me "
}
]
}
Only aggregate or mapReduce could exclude items from subarray in output. Shortest is to use $redact:
db.facebook.aggregate({
$redact:{
$cond:{
if:{$and:[{$not:"$username"},{$ne:["$user","bob"]}]},
then: "$$PRUNE",
else: "$$DESCEND"
}
}
})
Explanation:
$reduct would be applied to each subdocument starting from whole document. For each subdocument $reduct would either prune it or descend. We want to keep top level document, that is why we have {$not:"$username"} condition. It prevents top level document from pruning. On next level we have comments array. $prune would apply condition to each item of comments array. First condition {$not:"$username"} is true for all comments, and second condition {$ne:["$user","bob"]} is true for all subdocuments where user!="bob", so such documents would be pruned.
Update: in node.js with mongodb native driver
db.facebook.aggregate([{
$redact:{
$cond:{
if:{$and:[{$not:"$username"},{$ne:["$user","bob"]}]},
then: "$$PRUNE",
else: "$$DESCEND"
}
}
}], function(err,docs){})
One more thing: $prune is new operator and available only in MongoDB 2.6
The assemble.io documentation gives some examples of using simple JSON as a data source, such as:
{
"title": "Assemble" ,
"author": "Brian Woodward"
}
But, what if I wanted to use a more complex JSON structure for my data (to display a list of books on a single page)? How can that be done?
{
"books": [
{
"title": "Book A",
"author": "Fred"
},
{
"title": "Book 47",
"author": "Joe"
}
]
}
Let say your library.json contain:
{
"books": [
{
"title": "Book A",
"author": "Fred"
},
{
"title": "Book 47",
"author": "Joe"
}
]
}
Use {{each}} (Assemble use handlebarjs for default templating) to display a list of books on a single page:
{{#each library.books}}
{{title}} - {{author}}
{{/each}}
I have the following document structure:
{
"some_field": "some_data",
"entries": {
{"id": "some_id", "type": "some_type", "value": "some_value"},
{"id": "another_id", "type": "another_type", "value": {"foo": 1, "bar": "two"}
}
}
So I would like to map entries based on the "type" field.
Which maping type or flag should I use?
Or maybe I need to change my doc structure?
Could you use this one
{
"some_field":"some_data",
"entries":[{
"id":"some_id",
"type":"some_type",
"value":"some_value"
},
{
"id":"another_id",
"type":"another_type",
"value":{
"foo":1,
"bar":"two"
}
}]
}
I am using API to get data from the site.
I got those data like next:
1>
"tags": {
"data": [
{
"name": "action:archived"
},
{
"name": "archived"
},
{
"name": "inbox"
},
{
"name": "source:email"
}
]
}
2>
"tags": {
"data": [
{
"name": "inbox"
},
{
"name": "source:email"
}
]
}
And follow the manual, I could get the data only with tag "inbox" not the "archived" using the link like this: https://abc.com/DATA?tags=inbox, I tried and as you could guess, both data have the tag named "inbox", if I want to get the data without the tag "archived", what could I do?
Thank you for your time and any hint would be helpful.