Is there a way to ensure that one script runs before another in Meteor? I'm currently developing some software and using sample data for now. I'm a bit curious if there's a way that I can fill a particular collection only after another collection that it depends on has been filled
For example, An Invoices collection that has a patient_id: Patients.findOne(...) field that depends on the Patients collection actually having data. Is there a way to perform this other than having them on the same file, with Patients being filled before Invoices?
Assuming you are trying to create test data in the right order, then you can run the test data generator for Invoices in a Tracker.autorun. This will be run reactively:
Meteor.startup(()=>{
Tracker.autorun(()=>{
if ( Patients.find().count() && !Invoices.find().count() ){
populateInvoices();
}
});
});
Related
Currently, I built a database with the customer PO, the item they ordered and the quantity they ordered.
I have a separate report that I receive every day that tells me what item has been shipped and the reference customer PO and the quantity.
I wrote a python script that reads through the report and update the MongoDB database using a filter by looking at the customer PO and part number. However, I want to be able to log errors arising from this filter (for instance, cannot find any entry that fits the filter) and the event logs every time I update the database. Below is the filter I used and updating of the quantity.
filter = {'PO Number': customer_PO,'Part Number': customer_Part}
shipped_Qty = {"$inc":{'Shipped':customer_shippedQty}}
collection.update_one(filter, shipped_Qty)
Can anyone assist me for the event logger or error logger?
I tried to find whether the customer PO and part number exists first in the database but I believe that might not be very efficient in achieving my goal.
In my model I want to loop through the database which contains multiple columns (see example) by an event. The idea behind it is that I want to create dynamic events based on the rows in the database.
But I've no clue how to iterate through a database in anylogic and also was not able to find an example of a loop with a database.
The dummycode of my problem would look something like this:
For order in orderdatabase:
Create order based on (order.name, order.quantity, order.arrivaltime, order.deliverylocation)
Where order in the loop is every row of the database, and the value on which the creation is based based on the different column values of that specific row.
Can somebody give me a simple example of how to create such a loop for this specific problem.
Thanks in advance.
Use the database query wizard:
put your cursor into a code field
this will allow you to open the database wizard
select what you need (in your case, you want the "iterate over returned rows and do something" option
Click ok
adjust the dummy code to make it do what you want
For details and examples, check the example models and the AnyLogic help, explaining all options in detail.
I have a xml table listing Product ID and the status from the odata consumed. I have grouped the data(PFA) based on the concept of sorting and filtering.
I want to further group the Product ID with repetitive occurrence in the xml table and show the count of the grouped products.
Note: In my table I have a product called "Power Wheel Chair" with three occurrence. I want to group it as display only one power wheel chair with the count as 3 in another field.
Please provide your suggestions on how to accomplish this. Also do revert back for further queries.Grouping table
Regards,
Srinivasan
It would be best to have the server to handle aggregation of lines items into totals and have it to return the condensed set in a separate EntitySet (e.g. ProductCounts), that would look something like this:
[
{ product: A, count: 5 },
{ product: B, count: 7 }
]
Doing this on the server, has the benefit that a much smaller set of data is downloaded to the client. In the earlier example 12 records would have been downloaded instead of two. On top of that, the client doensn't need to do the processing and math, but this is delegated to the server. And that's great, because the server usually has the means to crunch large amounts of data efficiently.
If you still want to do the calculation client side, I would suggest writing a little code in the success handler of the ODataModel.read method that does the aggregation and pushes the result into a JSON model. You can then bind the JSON model to your table control.
Hopefully I can describe this correctly but I come from the RDBMS world and I'm building an inventory type application with Meteor. Meteor and Mongodb may not be the best option for this application but hopefully it can be done and this seems like a circumstance that many converts will run into.
I'm trying to forget many of the things I know about relational databases and referential integrity so I can get my head wrapped around Mongodb but I'm hung up on this issue and how I would appropriately find the data with Meteor.
The inventory application will have a number of drop downs but I'll use an example to better explain. Let's say I wanted to track an item so I'll want the Name, Qty on Hand, Manufacturer, and Location. Much more than that but I'm keeping it simple.
The Name and Qty on Hand are easy since they are entered by the user but the Manufacturer and the Location should be chosen in a drop down from a data driven list (I'm assuming a Collection of sorts (or a new one added to the list if it is a new Manufacturer or Location). Odds are that I will use the Autocomplete package as well but the point is the same. I certainly wouldn't want the end user to misspell the Manufacturer name and thereby end up with documents that are supposed to have the same Manufacturer but that don't due to a typo. So I need some way to enforce the integrity of the data stored for Manufacturer and Location.
The reason is because when the user is viewing all inventory items later, they will have the option of filtering the data. They might want to filter the inventory items by Manufacturer. Or by Location. Or by both.
In my relational way of thinking this would just be three tables. INVENTORY, MANUFACTURER, and LOCATION. In the INVENTORY table I would store the ID of the related respective table row.
I'm trying to figure out how to store this data with Mongodb and, equally important, how to then find these Manufacturer and Location items to populate the drop down in the first place.
I found the following article which helps me understand some things but not quite what I need to connect the dots in my head.
Thanks!
referential data
[EDIT]
Still working at this, of course, but the best I've come up with is to do it normalized way much like is listed in the above article. Something like this:
inventory
{
name: "Pen",
manufacturer: id: "25643"},
location: {id: "95789"}
}
manufacturer
{
name: "BIC",
id: "25643"
}
location
{
name: "East Warehouse",
id: "95789"
}
Seems like this (in a more simple form) would have to be an extremely common need for many/most applications so want to make sure that I'm approaching it correctly. Even if this example code were correct, should I use an id field with generated numbers like that or should I just use the built-in _id field?
I've come from a similar background so I don't know if I'm doing it correctly in my application but I have gone for a similar option to you. My app is an e-learning app so an Organisation will have many Courses.
So my schema looks similar to yours except I obviously have an array of objects that look like {course_id: <id>}
I then registered a helper than takes the data from the organisation and adds in the additional data I need about the courses.
// Gets Organisation Courses - In your case could get the locations/manufacturers
UI.registerHelper('organisationCourses', function() {
user = Meteor.user();
if (user) {
organisation = Organisations.findOne({_id: user.profile.organisation._id});
courses = organisation.courses.courses;
return courses;
} else {
return false;
}
});
// This takes the coursedata and for each course_id value finds and adds all the course data to the object
UI.registerHelper('courseData', function() {
var courseContent = this;
var course = Courses.findOne({'_id': courseContent.course_id});
return _.extend(courseContent, _.omit(course, '_id'));
});
Then from my page all I have to call is:
{{#each organisationCourses}}
{{#with courseData}}
{{> admListCoursesItem}}
{{/with}}
{{/each}}
If I remember rightly I picked up this approach from an EventedMind How-to video.
I wonder, How do I change a live data schema with MongoDB ?
For example If I have "Users" collection with the following document:
var user = {
_id:123312,
name:"name",
age:12,
address:{
country:"",
city:"",
location:""
}
};
now, in a new version of my application, if I add a new property to "User" entity, let us say weight, tall or adult ( based on users year ), How to change all the current live data which does not have adult property. I read MapReduce and group aggregation command but, they seem to be comfortable and suitable for analytic operation or other calculations, or I am wrong.
So what is the best way to change your current running data schema in MongoDB ?
It really depends upon your programming language. MongoDB is really good at having a dynamic schema. I think your pattern of thought at the moment is too SQL related whereby you believe that all rows, even if they do not yet have a value, must have the new field.
The reality is quite different. The rows which have nothing meaningful to put into them do not require the field and you can, in your application, just check to see if the returned document has a value, if not then you can assume, as in a fixed SQL schema, that the value is null.
So this is one aspect where MongoDB shines, is the fact that you don't have to apply that new field to the entire schema on demand, instead you can lazy fill it as data is entered by the user.
So just code the field into your application and let the user do the work for you.
The best way to add this field is to write a loop, in maybe the console close or on the primary of your replica (if you have one, otherwise just on the server), like so:
db.users.find().forEach(function(doc){
doc.weight = '44 stone';
db.users.save(doc);
});
That is currently the best way to do something like what your asking.