简体   繁体   中英

how to use 'sort' when searching the cloudant database?

I am using Nano to connect to the database on NodeJS.

The api is: db.search(designname, searchname, [params], [callback])

In the params, I tried {q:"name:'39'"}, it can work, but if I add 'sort', then it never works. For example: {"name:'39'", sort:'count'}, {"name:'39'","['count']"}. However when I use the url to commit same operation like '/showall?q=name:39&sort="count"', and it works. I also tried {"name:'39'", limit:3}, it also work.

I just do not know how to use 'sort' in the JS code.

The sort parameter needs to be a JSON formatted string. In your url example, you are JSON formatting the string with /showall?q=name:39&sort="count" . To replicate this in code you would need to do:

db.search(ddocname, searchname, {"name":39', sort:'"count"'});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM