View Couchdb视图查询
你能帮我创建一个视图吗。以下是要求View Couchdb视图查询,view,couchdb,View,Couchdb,你能帮我创建一个视图吗。以下是要求 select * from personaccount where name="srini" and user="pup" order by lastloggedin 我必须将名称和用户作为输入发送到视图,数据应该按lastloggedin排序 下面是我创建的视图,但它不起作用 { "language": "javascript", "views": { "sortdatetimefunc": { "m
select * from personaccount where name="srini" and user="pup" order by lastloggedin
我必须将名称和用户作为输入发送到视图,数据应该按lastloggedin排序
下面是我创建的视图,但它不起作用
{
"language": "javascript",
"views": {
"sortdatetimefunc": {
"map": "function(doc) {
emit({
lastloggedin: doc.lastloggedin,
name: doc.name,
user: doc.user
},doc);
}"
}
}
}
这是curl命令iam,它使用:
http://uta:password@localhost:5984/personaccount/_design/checkdatesorting/_view/sortdatetimefunc?key={\"name:srini\",\"user:pup\"}
我的问题是
由于排序将在键上完成,我希望它在lastloggedin上,所以我在emit函数中也给出了它
但iam仅将名称和用户作为参数传递。我们需要传递我们在密钥中给出的所有参数吗
首先,我想向你转达我的答复,我也做了同样的事情,我也犯了错误。请帮忙 你能在你的电脑上试试这个吗,我正在发布所有命令:
curl -X PUT http://uta:password@localhost:5984/person-data
curl -X PUT http://uta:password@localhost:5984/person-data/srini -d '{"Name":"SRINI", "Idnum":"383896", "Format":"NTSC", "Studio":"Disney", "Year":"2009", "Rating":"PG", "lastTimeOfCall": "2012-02-08T19:44:37+0100"}'
curl -X PUT http://uta:password@localhost:5984/person-data/raju -d '{"Name":"RAJU", "Idnum":"456787", "Format":"FAT", "Studio":"VFX", "Year":"2010", "Rating":"PG", "lastTimeOfCall": "2012-02-08T19:50:37+0100"}'
curl -X PUT http://uta:password@localhost:5984/person-data/vihar -d '{"Name":"BALA", "Idnum":"567876", "Format":"FAT32", "Studio":"YELL", "Year":"2011", "Rating":"PG", "lastTimeOfCall": "2012-02-08T19:55:37+0100"}'
以下是您所说的我创建的视图:
{
"_id": "_design/persondestwo",
"_rev": "1-0d3b4857b8e6c9e47cc9af771c433571",
"language": "javascript",
"views": {
"personviewtwo": {
"map": "function (doc) {\u000a emit([ doc.Name, doc.Idnum, doc.lastTimeOfCall ], null);\u000a}"
}
}
}
I have fired this command from curl command :
curl -X GET http://uta:password@localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=["SRINI","383896"]&endkey=["SRINI","383896",{}]descending=true&include_docs=true
我得到了这个错误:
[4] 3000
curl: (3) [globbing] error: bad range specification after pos 99
[5] 1776
[6] 2736
[3] Done descending=true
[4] Done(3) curl -X GET http://uta:password@localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=["SRINI","383896"]
[5] Done endkey=["SRINI","383896"]
我不知道这个错误是什么
我也尝试过以下面的方式传递参数,但没有帮助
curl -X GET http://uta:password@localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?key={\"Name\":\"SRINI\",\"Idnum\": \"383896\"}&descending=true
但我在转义序列上有不同的错误
总的来说,我只希望通过以下视图满足此查询:
select * from person-data where Name="SRINI" and Idnum="383896" orderby lastTimeOfCall
我关心的是如何从curl命令传递多个参数,因为如果我采用上述方法,会出现很多错误。首先,您需要使用数组作为键。我将使用:
function (doc) {
emit([ doc.name, doc.user, doc.lastLoggedIn ], null);
}
这基本上是按名称、用户和lastLoggedIn的顺序输出所有文档。您可以使用以下URL进行查询
/_design/checkdatesorting/_view/sortdatetimefunc?startkey=["srini","pup"]&endkey=["srini","pup",{}]&include_docs=true
其次,请注意,我没有将doc
作为查询的值输出。它会占用更多的磁盘空间,尤其是当您的文档相当大时。只需使用include\u docs=true
最后,请参考CouchDB,它非常有用。我刚刚偶然发现了这个问题。您得到的错误是由于未转义此命令引起的:
curl -X GET http://uta:password@localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=["SRINI","383896"]&endkey=["SRINI","383896",{}]descending=true&include_docs=true
&字符在命令行中有特殊含义,当它是实际参数的一部分时,应该转义。
因此,您应该在大URL周围加引号,并转义其中的引号:
curl -X GET "http://uta:password@localhost:5984/person-data/_design/persondestwo/_view/personviewtwo?startkey=[\"SRINI\",\"383896\"]&endkey=[\"SRINI\",\"383896\",{}]descending=true&include_docs=true"
你好,多米尼克,首先我想对你的回复表示感谢,我也做了同样的事情,我也犯了错误