有没有办法从 Couchdb 中获得更清洁的 JSON?
Is there a way of getting a cleaner JSON out of Couchdb?
我想知道是否有一种方法可以仅使用 Couchdb 中的文档来获得更清洁的 JSON,而不是先在 "rows" 下获取,然后在 "doc"[=13= 下获取]
这是默认输出
{
"total_rows":1,
"offset":0,
"rows":[
{
"id":"7d9fd5824f9029186c1eec1bda005e75",
"key":"7d9fd5824f9029186c1eec1bda005e75",
"value":{
"rev":"1-f99879f67cfd27685f92c884c236a0fd"
},
"doc":{
"_id":"7d9fd5824f9029186c1eec1bda005e75",
"_rev":"1-f99879f67cfd27685f92c884c236a0fd",
"title":"Hello World",
"messeges":"This is the first messege. Helloo there"
}
}
]
}
这是期望的输出:
{
"_id":"7d9fd5824f9029186c1eec1bda005e75",
"_rev":"1-f99879f67cfd27685f92c884c236a0fd",
"title":"Hello World",
"messeges":"This is the first messege. Helloo there"
}
谢谢
看到你的代码会很有用。我怀疑这是 alldocs api? If you know the ID of the document you want you can use the get api 的输出,其中 returns 是您想要的 JSON。否则你必须循环遍历 "rows" 即
for (x in results.rows) {...}
然后使用 x.doc 得到你的 JSON。
感谢大家的帮助。
我想出了一种在 Node js 中通过使用附加到查询
的映射函数来实现的方法
在纳米页面中,他们将其列为
alice.list().then((body) => {
body.rows.forEach((doc) => {
console.log(doc);
});
});
相反,我是这样使用的
alice.list().then((body) => {
var result = body.rows.map( (x) => {
return x.doc
});
console.log(result);
});
这对我有用。
在 couchdb 和一般数据库之前仍然是新的。
我想知道是否有一种方法可以仅使用 Couchdb 中的文档来获得更清洁的 JSON,而不是先在 "rows" 下获取,然后在 "doc"[=13= 下获取]
这是默认输出
{
"total_rows":1,
"offset":0,
"rows":[
{
"id":"7d9fd5824f9029186c1eec1bda005e75",
"key":"7d9fd5824f9029186c1eec1bda005e75",
"value":{
"rev":"1-f99879f67cfd27685f92c884c236a0fd"
},
"doc":{
"_id":"7d9fd5824f9029186c1eec1bda005e75",
"_rev":"1-f99879f67cfd27685f92c884c236a0fd",
"title":"Hello World",
"messeges":"This is the first messege. Helloo there"
}
}
]
}
这是期望的输出:
{
"_id":"7d9fd5824f9029186c1eec1bda005e75",
"_rev":"1-f99879f67cfd27685f92c884c236a0fd",
"title":"Hello World",
"messeges":"This is the first messege. Helloo there"
}
谢谢
看到你的代码会很有用。我怀疑这是 alldocs api? If you know the ID of the document you want you can use the get api 的输出,其中 returns 是您想要的 JSON。否则你必须循环遍历 "rows" 即
for (x in results.rows) {...}
然后使用 x.doc 得到你的 JSON。
感谢大家的帮助。 我想出了一种在 Node js 中通过使用附加到查询
的映射函数来实现的方法在纳米页面中,他们将其列为
alice.list().then((body) => {
body.rows.forEach((doc) => {
console.log(doc);
});
});
相反,我是这样使用的
alice.list().then((body) => {
var result = body.rows.map( (x) => {
return x.doc
});
console.log(result);
});
这对我有用。
在 couchdb 和一般数据库之前仍然是新的。