MongoDB NodeJS Query and paginate multiple collection - node.js

I am dealing with a case where I need to render of listing of several entities on one page, with one pagination.
I.g.: Given 3 collections, People, Robots and ETs. Now I'd need to list them all in a /everybody route that renders a listing page with a pagination and some filters.
As far as I can tell the only way to do that in MongoDB is to query each collection manually and handle the pagination in the application. Are there any other/better ways ?

Related

How to Combine Multiple View Updates Into One ListView?

I have multiple views in multiple nsf databases that I want to perform a view.update on, build an array of records, and show the results in one ListView. What would be the best way to do this in regards to performance? One idea that came to mind was to:
Perform .update() method on views
In callback of each update, push records to a (global?) array
Set array to ListView
Am I thinking about this correctly? Is there an example of doing this in Domino To Go?
Thanks for any tips.
I would chain the .update() methods on the views and in the callback of the final update I would sue a DTGDatabase object with getAllEntriesByKey() method to get the records, it's faster than using NotesView.getAllEntriesByKey of each view.
Or use DTGDatabase.getAllEntriesBySQL with a proper SQL statement, that way you can do a JOIN and it's the fastest option.

Zend Framework 2 Paginating Search Results

I'm making a complex search form with a lot of inputs to query and I want to paginate the search results using Zend Framework 2.
I've found a few people who are trying to do something similar but I have yet to find a good solution.
Some people suggested switching to $_GET method instead of $_POST but i would prefer to avoid this because of the number of form elements.
The results are coming up fine, but as soon as i try to navigate to the second page, the query is lost and it is essentially paginating all records on the table.
What is the best way to store the original search query so that the paginated results are the actual results?
I can't imagine ZF2 doesn't have an easy way to paginate $_POST results but I haven't been able to figure it out yet
well you either need to repost the search parameters on every page request or keep the search parameters in a session and on the second request check if the request is get or post and use the session if it is get

Efficient Pagination with Flask and Mongoengine

I have a Flask app with which I would like to display paginated tables of data from a MongoDB Collection. However, there are potentially very many documents in this collection, so I would like to be loading them lazily - only loading the ones which are about to be displayed.
My problem is that on one page in my app, I would like to paginate:
Stuff.objects()
But on different pages I would like to paginate:
Stuff.objects(__raw__=query) or Stuff.objects(message__in=Message.objects(__raw__=query))
Calling any of those particular functions automatically loads all of the relevant objects into memory (as I discovered by running locals()) so I need to paginate the calls with:
Stuff.objects().skip(number).limit(pagelength), or
Stuff.objects(__raw__=query).skip(number).limit(pagelength)
So it would seem that I need a Paginator class which I can simply pass Report into, then somehow specify the query information.
Can anyone recommend a solution?
Try using the paginator from flask-mongoengine You can use it like so:
paginator = Pagination(Post.objects, 1, 10)
print paginator.items

CouchDB views - Multiple join... Can it be done?

I have three document types MainCategory, Category, SubCategory... each have a parentid which relates to the id of their parent document.
So I want to set up a view so that I can get a list of SubCategories which sit under the MainCategory (preferably just using a map function)... I haven't found a way to arrange the view so this is possible.
I currently have set up a view which gets the following output -
{"total_rows":16,"offset":0,"rows":[
{"id":"11098","key":["22056",0,"11098"],"value":"MainCat...."},
{"id":"11098","key":["22056",1,"11098"],"value":"Cat...."},
{"id":"33610","key":["22056",2,"null"],"value":"SubCat...."},
{"id":"33989","key":["22056",2,"null"],"value":"SubCat...."},
{"id":"11810","key":["22245",0,"11810"],"value":"MainCat...."},
{"id":"11810","key":["22245",1,"11810"],"value":"Cat...."},
{"id":"33106","key":["22245",2,"null"],"value":"SubCat...."},
{"id":"33321","key":["22245",2,"null"],"value":"SubCat...."},
{"id":"11098","key":["22479",0,"11098"],"value":"MainCat...."},
{"id":"11098","key":["22479",1,"11098"],"value":"Cat...."},
{"id":"11810","key":["22945",0,"11810"],"value":"MainCat...."},
{"id":"11810","key":["22945",1,"11810"],"value":"Cat...."},
{"id":"33123","key":["22945",2,"null"],"value":"SubCat...."},
{"id":"33453","key":["22945",2,"null"],"value":"SubCat...."},
{"id":"33667","key":["22945",2,"null"],"value":"SubCat...."},
{"id":"33987","key":["22945",2,"null"],"value":"SubCat...."}
]}
Which QueryString parameters would I use to get say the rows which have a key that starts with ["22945".... When all I have (at query time) is the id "11810" (at query time I don't have knowledge of the id "22945").
If any of that makes sense.
Thanks
The way you store your categories seems to be suboptimal for the query you try to perform on it.
MongoDB.org has a page on various strategies to implement tree-structures (they should apply to Couch and other doc dbs as well) - you should consider Array of Ancestors, where you always store the full path to your node. This makes updating/moving categories more difficult, but querying is easy and fast.

Nested databases in CouchDB

It seems you are unable to nest databases in CouchDB. How do people work around this limitation? For example, assume I want to create a blogging engine where each domain has a separate database. Within each database I might want a Users database, an Orders database, etc. to contain the various user documents, order documents, and so forth.
The obvious way seems to be a flat structure where the database name demarcates the artificial boundary between database nesting levels with a hyphen:
myblog.com-users
myblog.com-posts
myblog.com-comments
anotherblog.com-users
anotherblog.com-posts
anotherblog.com-comments
...hundreds more...
Another solution would be to keep the lower-level databases and mark each document with the top-level value:
users database containing a document User1, with field instance="Test" or a field domain="myblog.com"
I think you're misusing the term database here. There is no reason you can't store the users, posts, and comments data in a single couchdb database. Your couchdb views can separate out the user documents from the posts documents, from the comments documents.
example map function for user documents in a couchdb database:
function(doc) {
if (doc.type = 'user') { // only return user documents
emit([doc.domain, doc.id], doc); // the returned docs will be sorted by domain
}
}
see View Api for ways to restrict that views results by domain using startkey and endkey with view collation.
I think the best solution is to have one database per domain, each storing domain specific data.

Resources