I have some documents in a database sitting in a couchdb server. I'm struggling to create a view that works. The documents are formatted as such:
{
"_id": "2018_1_17",
"_rev": "2-d6b8e691925e9bae697c2df054eb77f0",
"name1.com": {
"Title": "string",
"Date": "Thu, 11 Jan 2018 08:55:21 +0000",
"Site": "string",
"Description": "string"
},
"name2.com": {
"Title": "title",
"Date": "Thu, 11 Jan 2018 06:20:43 +0000",
"Site": "string",
"Description": "string"
},
...
I've tried a couple of views, for example:
function (doc) {
if(doc.Title && doc.Date) {
emit(doc.Title, doc.Date);
}
}
etc.
When I do a curl though, it returns the javascript code of the view and no actual results.
I would guess my map function is just wrong. Any ideas?
Thanks!
You didn't mention your curl command and I don't know why it is not working, but there is something else which doesn't look right:
In your view function your using doc.Title and doc.Date, however, in your document, there is not a doc.Title field and there is not a doc.Date field, since Title and Date are sub-fields inside name1.com and name2.com.
Sorry for not getting back sooner. It seems my curl command wasn't quite right.
It was:
curl http://127.0.0.1:5984/rss_feeds/_design/_by_date/
It needs to be:
curl http://127.0.0.1:5984/rss_feeds/_design/_by_date/_view/_by_date
Related
I have a sentence how do we format that string to support and assign to a variable?
let words="2021-08-03 14:00:49.0430 Info Message Template Auto Format enabled
2021-08-03 14:00:49.4297 Info Adding target ConsoleTarget(Name=consoleLogger)
2021-08-03 14:00:49.8396 Info Found 48 configuration items
2021-08-03 14:00:49.8716 Info Configuration initialized.
2021-08-03 14:00:49.8716 Info NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.6.8.10751. Product version: 4.6.8.
{ "time": "2021-08-03 14:00:50.0625", "thread": "1", "level": "WARN", "message": "Storing keys in a directory '\/root\/.aspnet\/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.", "properties": "path=\/root\/.aspnet\/DataProtection-Keys, EventId_Id=60, EventId=60" }
{ "time": "2021-08-03 14:00:50.4593", "thread": "1", "level": "WARN", "message": "No XML encryptor configured. Key {153434f7-eab5-4326-a0aa-5973fb78b`ecb} may be persisted to storage in unencrypted form.", "proper`ties": "KeyId=153434f7-eab5-4326-a0aa-5973fb78becb, EventId_Id=35, EventId=35" }
{ "time": "2021-08-03 14:01:14.0448", "thread": "5", "level": "WARN", "message": "Failed to determine the https port for redirect.", "properties": "EventId_Id=3, EventId_Name=FailedToDeterminePort, EventId=FailedToDeterminePort" }"
console.log(words)
When I tried to do some string methods to in it its not allowing me to perform any action because of the special characters in the sentence.
How can we support this type of sentence to perform string operations?
Expected output: I should be able to get the log.
You may need to use backtick (`) at the start and the end of string and add the escaping sequence \ before any backtick in the middle of the text. Here is the snippet:
let words = `"2021-08-03 14:00:49.0430 Info Message Template Auto Format enabled
2021 - 08 - 03 14: 00: 49.4297 Info Adding target ConsoleTarget(Name = consoleLogger)
2021 - 08 - 03 14: 00: 49.8396 Info Found 48 configuration items
2021 - 08 - 03 14: 00: 49.8716 Info Configuration initialized.
2021 - 08 - 03 14: 00: 49.8716 Info NLog, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = 5120e14c03d0593c.File version: 4.6.8.10751.Product version: 4.6.8.
{ "time": "2021-08-03 14:00:50.0625", "thread": "1", "level": "WARN", "message": "Storing keys in a directory '\/root\/.aspnet\/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed.", "properties": "path=\/root\/.aspnet\/DataProtection-Keys, EventId_Id=60, EventId=60" }
{ "time": "2021-08-03 14:00:50.4593", "thread": "1", "level": "WARN", "message": "No XML encryptor configured. Key {153434f7-eab5-4326-a0aa-5973fb78b\`ecb} may be persisted to storage in unencrypted form.", "proper\`ties": "KeyId=153434f7-eab5-4326-a0aa-5973fb78becb, EventId_Id=35, EventId=35" }
{ "time": "2021-08-03 14:01:14.0448", "thread": "5", "level": "WARN", "message": "Failed to determine the https port for redirect.", "properties": "EventId_Id=3, EventId_Name=FailedToDeterminePort, EventId=FailedToDeterminePort" } "
`
console.log(words)
I have an application created in Node.js with a Rethinkdb database, I load images from the application, but from the Data Explorer, to which you can connect from localhost: 8080, I can not delete the loaded elements.
// This is how I show the elements that the table has Data Explorer
r.db("xxxxxxxxxx").table('images')
// And this is, or that shows
{
"createdAt": Sun Jul 29 2018 16:19:27 GMT+00:00 ,
"id": "17aac165-e885-4278-9cf2-8a71bca65fe3" ,
"publicId": "0IERfW4T5wfcjhFjGNftZh" ,
"src": https:xxxxxxxxxxxxxxxxxxxxxxxx1532881165551.jpg, »
"tags": [ ],
"user": {
"avatar": "www.gravatar.com/avatar/c17a64a79d5bb880c9b002458240fa92" ,
"name": "" ,
"username": "pedrito"
},
"userId": "pedrito"
}
For more than what I check the javascript documentation of Rethinkdb: (https://www.rethinkdb.com/api/javascript/)
I can not find a way to remove the elements of the images from the table one by one. It's there, but I cannot find the way. The most I can see is how to remove users from another table: r.db ("xxxxxxxx"). Table ("users"). Filter (r.row ['username'] = 'pedrito'). delete (). runpero
I can not delete the images in the same way. I want to do it from Data Explorer, from the graphical part of Rethinkdb. Thanks.
This question is a bit unclear, if you mean deleting the entire document:
r.db("database").table("table").get("document_id").delete()
database, table, and document_id are placeholders
database: The database the table you are trying to delete from is in
table: The table the document you want to delete is in
document_id: The primary key of the document (default id) that you want to delete
so in this
{
"createdAt": Sun Jul 29 2018 16:19:27 GMT+00:00 ,
"id": "17aac165-e885-4278-9cf2-8a71bca65fe3" ,
"publicId": "0IERfW4T5wfcjhFjGNftZh" ,
"src": https:xxxxxxxxxxxxxxxxxxxxxxxx1532881165551.jpg, »
"tags": [ ],
"user": {
"avatar": "www.gravatar.com/avatar/c17a64a79d5bb880c9b002458240fa92" ,
"name": "" ,
"username": "pedrito"
} ,
"userId": "pedrito"
}
Your primary key is likely ID, so you would use
r.db("xxx").table("images").get("17aac165-e885-4278-9cf2-8a71bca65fe3").delete()
https://rethinkdb.com/api/javascript/#delete
else, if you mean deleting a specific key, go check this answer to another question https://stackoverflow.com/a/18580552
EDIT: Delete all
r.db('database').table('table').forEach((entry)=>{
return r.db('database').table('table').get(entry('id')).delete();
});
this will delete absolutely EVERYTHING in the table!
EDIT: Delete where key = value
r.db('database').table('table').filter({key:"value"}).forEach((entry)=>{
return r.db('database').table('table').get(entry('id')).delete();
});
This would delete everything in the table where key: "value".
I wanted to determine the datatype of a field in my JSON document in MongoDB. Is it possible to do so? Example if I have
{
"created_at": "Fri Aug 04 05:42:03 +0000 2017",
"id": 893346273255866400,
"id_str": "893346273255866368"
}
I wanted to know what type of values "created_at" accepts so I can formulate a query in my MongoDB
You can use the typeof operater to return the type of value in MongoDB and you can also query by a specific type by using $type operator in query.
e.g.
db.inventory.find( { price: { $type: "decimal" } } )
For more information see https://docs.mongodb.com/manual/core/shell-types/#check-types-in-shell
I have a below output from the server.And I want to get the "result" from the JSON input.
My JSON Input is
{
"header":{
"type":"esummary",
"version":"0.3"
},
"result":{
"28885854":{
"uid":"28885854",
"pubdate":"2017 Sep 8",
"epubdate":"2017 Sep 8",
"source":"J Org Chem",
}
}
}
And I prefer only javascript.Anyone help me to do this.
EDIT :
I tried the code to get JSON from server
var json = JSON.stringify(temp1);
console.log(json)
My original output in the console was like this.
"
{"header":{"type":"esummary","version":"0.3"},"result":{"28885854":{"uid":"28885854","pubdate":"2017 Sep 8","epubdate":"2017 Sep 8","source":"J Org Chem","authors":[{"name":"Farmer LA","authtype":"Author","clusterid":""},{"name":"Haidasz EA","authtype":"Author","clusterid":""},{"name":"Griesser M","authtype":"Author","clusterid":""},{"name":"Pratt DA","authtype":"Author","clusterid":""}],"lastauthor":"Pratt DA","title":"Phenoxazine: A Privileged Scaffold for Radical-Trapping Antioxidants.","sorttitle":"phenoxazine a privileged scaffold for radical trapping antioxidants","volume":"","issue":"","pages":"","lang":["eng"],"nlmuniqueid":"2985193R","issn":"0022-3263","essn":"1520-6904","pubtype":["Journal Article"],"recordstatus":"PubMed - as supplied by publisher","pubstatus":"10","articleids":[{"idtype":"pubmed","idtypen":1,"value":"28885854"},{"idtype":"doi","idtypen":3,"value":"10.1021/acs.joc.7b02025"},{"idtype":"rid","idtypen":8,"value":"28885854"},{"idtype":"eid","idtypen":8,"value":"28885854"}],"history":[{"pubstatus":"entrez","date":"2017/09/09 06:00"},{"pubstatus":"pubmed","date":"2017/09/09 06:00"},{"pubstatus":"medline","date":"2017/09/09 06:00"}],"references":[],"attributes":["Has Abstract"],"pmcrefcount":"","fulljournalname":"The Journal of organic chemistry","elocationid":"doi: 10.1021/acs.joc.7b02025","doctype":"citation","srccontriblist":[],"booktitle":"","medium":"","edition":"","publisherlocation":"","publishername":"","srcdate":"","reportnumber":"","availablefromurl":"","locationlabel":"","doccontriblist":[],"docdate":"","bookname":"","chapter":"","sortpubdate":"2017/09/08 00:00","sortfirstauthor":"Farmer LA","vernaculartitle":""},"uids":["28885854"]}}
"
I think all you're looking for is .result. Perhaps you also want JSON.parse(...) if you have just the JSON string so far.
var obj = {
"header": {
"type": "esummary",
"version": "0.3"
},
"result": {
"28885854": {
"uid": "28885854",
"pubdate": "2017 Sep 8",
"epubdate": "2017 Sep 8",
"source": "J Org Chem",
}
}
};
console.log(obj.result);
// To address edits above and comments below:
console.log(obj.result["28885854"].source);
When I use the aws codecommit api to select one commit I recieve the following json response:
{
"commit": {
"additionalData": "",
"committer": {
"date": "1505892072 +0200",
"name": "some name",
"email": "some#email.com"
},
"author": {
"date": "1505892072 +0200",
"name": "some name",
"email": "some#email.com"
},
"treeId": "c06c3kr2890sdf80f4e7f1234998cc18c2d672a6",
"parents": [
"8jghe808f7f5acc8f067dfg73f88ebfc6e5dfg82"
],
"message": "some message"
}
}
Now I want to parse the commit date 1505892072 +0200 in javascript. For this the function Date.parse(commtiDate) doesn't work because of the confusing format of the date.
In the example response of the AWS documentation it seems as if the format below is the standard format for api response (code commit api reference).
Have someone an idea how this format works and how to parse it in javascript?
I'm not sure about the +0200 but check the following:
var seconds = "1505892072";
var d = new Date(0);
d.setUTCSeconds(seconds);
Possible timezone adjustments still to be made ;)