What can be an alternative to mongoose populate in native mongodb driver where my query may return multiple documents - reference

What can be an alternative to mongoose populate for mongodb driver where my query may return multiple documents and each document can have multiple children(max 5-6) stored in different collection. I want each document populated with children props.
fx.
a user has multiple orders and each order has many items(each order only stores the id of an item). Now I've a query to get orders between specific time period and that will reurn multiple orders and now i want these orders to be populated with item(fx item price, item size)
one potential solution could be get all orders and make 5-6(no. of items) additional query, which i assume to be a performance bottleneck
*Nodejs mongo driver

Related

Is there any way to find distinct documents in mongo using nodejs

I actually want To display Full documents Without duplication
When I use distinct i can only display one particular field
How to display all fields without selecting that document which is repeated
Each document in MongoDB contains an _id field which must be unique in the collection. Hence, it is not possible to have two identical documents in a collection. Ergo, iterating a collection with no conditions will return all unique documents (which are all documents in the collection).

Snaplogic querying two sources and joining data together

I am trying to build a Pipeline which queries out my Sales records (as one Read activity)
Now in this Sales schema there are fields that reference a People table however its not a direct connection as there is a Many-to-Many relationship.
So what I need to do is query my PeopleToSales table for all related records and populate them in a flat structure in my subsequent JSON object.
How can I built two objects together and join them based on Sales ID? Also in the event there are multiple matches how can I choose the first one?
You can read both the Sales records and the PeopleToSales table and then use the Join snap to merge the relevant documents based on whatever ID that defines the relation between them.
After that, you can use the Group By Fields snap to group the documents based on Sales ID.
You can add the Sales ID field (say - $sales_id) in the Fields list in the settings and it will group documents based on the Sales ID.
Also, when using the Group By Fields snap, you first have to sort the documents based on the keys. So, use a Sort snap before the Group By Fields snap.
As far as getting the first object is concerned, after the group-by, you can just get the 0th element of the list (say group[0]).
Please refer to - SnapLogic Docs - Group By Fields

Deleting mongodb subdocument on certain date

I have a collection which stores document that can have multiple subdocument (e.g. a group collection with multiple votings). My goal is to delete certain subdocuments on a certain date. I thought about using a package like "agenda" to cron-like delete certain subdocuments. Are there any more efficient or easier ways to do that

Nodejs mongoose: how can I find a subset of all documents?

I have a collection in mongodb that has more than 100000 documents. Each time I apply Model.find(), it returns all documents in an array.
But for some reasons like unnecessary data or performance, speed of the query, I just want to find document that is:
Starting with first document
The second document will be the 300th document
The third document will be the 600th document
...
The final document will be the 100000th document
Is there any mongoose query for that?

Data reference and updation in cassandra tables

I have a table Called 'usertab' to store user details such as:
userid uuid,
firstname text,
lastname text
email text
gender int
image text
Most of the other tables contains userid as a field for referencing 'usertab',
but when I retrieve data from other table, I need to execute another select query to get user details.
So if 10,000 or more data retrieved, same number of select query executed for getting user details. This makes our system slow.
So we add usertab fields such as firstname,lastname, gender, image in other tables in addition to userid field.
So on data retrieval, the system become fast, but we faced another problem. If any changes in usertab table such as change in firstname, lastname, gender or image, we need to update other tables that contains user details. If we consider huge amount of data in other tables, how can I handle this?
We are using lucene index and C#.
Cassandra writes significantly faster and more efficient than reads.
That's why cassandra prefer Denationalization over normalization
Denormalization is the concept that a data model should be designed so that a given query can be served from the results from one row and query. Instead of doing multiple reads from multiple tables and rows to gather all the required data for a response, instead modify your application logic to insert the required data multiple times into every row that might need it in the future This way, all required data can be available in just one read which prevents multiple lookups.
When executing multiple update you can use executeAsync.
Session allows asynchronous execution of statements (for any type of statement: simple, bound or batch) by exposing the ExecuteAsync method.
//Execute a statement asynchronously using await
var rs = await session.ExecuteAsync(statement);
Source : https://www.hakkalabs.co/articles/cassandra-data-modeling-guide

Resources