What happens if you add item twice to Collection? - collections

What happens if you try to add an item to a Collection that already exists in the Collection?
Let's say you have a Collection full of integers and you try to add an integer that is already in the Collection.

Simply put if you add an item to a collection twice, it will be in the collection twice.
If you add it with a key then that needs to be unique.

If you try to add something with the same key as a key already in the collection, it throws an error (docs). You can add the same object to a collection twice as long as you use different keys for it.
Side note: Microsoft ended all official support for the VB6 development environment nearly four years ago. The runtime remains supported at least through Windows 7 (e.g., so existing apps continue to run). See this other question and its answers for more details.

Related

Firestore paginate documents for quiz app

I am building a quiz app and I am struggling about data structure in firebase.
Actually, I have two collections:
Questions collection, containing one document foreach question
Users Answers collection, containing one document foreach user. Inside user's document, there is one map per answered question where I store if question has been answered and if question has been right answered.
So, where is the problem ? For my app, I need two things:
Fetch list of a specific user answers. Actually there is no problem because I can query users answers collection for a specific user and retrieve all his answers within a single document.
Fetch list of a questions never answered by user. This is a quiz app, so it is mandatory to show questions never answered by user to progress in the game.
The current (not best) solution is this : when the user launch the app, I request all questions, get his answers and then I can know which question I should show to user and the ones I shouldn't. The problem of this solution is that I have to query all the questions documents so it represents a large number of reads (and firebase bill by number of reads 🙃).
I would like to paginate the number of questions to show to user (so questions never answered) to avoid extra-billing but I can't figure how to request them.
I tried to use not-in clause but it is limited to 10 items and I have a lot more than 10 questions.
I would like to know if you have any ideas to bypass this problem. Hope I'm clear enough.
Firestore doesn't support using the results of a query to exclude documents from another query. There are no SQL-like joins that query across documents in multiple collections.
If the provided inequality filter (10 items max) isn't sufficient for your use case, I'm afraid you're stuck with the solution you have now by filtering the results in the client app.
Some developers might choose to duplicate data into a SQL database to make these kinds of queries possible, but you'll have to decide for yourself if that's worthwhile.
We can consider this, I am wondering this could make your idea work.
This will only work when the users you know are constant.
Every questions docs need to have this property: not_answered_by
And set all users' ids list inside this property initially for all questions.
Once a user answered against one question then update certain question doc to remove that user id from not_answered_by So like this below, I remove user who has id:ccccc inside not_answered_by list from question :PXxzLaZp4kDSzewo7kht when user answered on that question.
Then you can run this query .where("not_answered_by", "array-contains", user_id) against questions collection to get all questions not answered by selected user.
If you have this structure of questions collection, then the powerful advantage is that you don't have to query double to get questions not answered by user, which does cost time and money. The remove action from not_answered_by doesn't affect speed low because you know which user id to be removed from which question id.
One tip: if you dont want to set not_answered_by to have all users' id list initially then just have another property: is_answer_started to set false for all questions. And whenever question is started to be answered then set not_answered_by to have all users' list.
not_answered_by is array of strings and it doesn't affect to your cost of firebase, important fact on your side is getting result in cheap and fast right?
Important to note: this is case of users' id list are constant, this doesn't work if users collection is dynamic which means user is added dynamically so please think this is a tricky method but I think it is best approach for now. PS: Firebase query doesn't support array_not_contains which I was about to find and use it. We can approach this in javascript via array includes function you know. :)
Vice versa, you can have answerd_by property inside question doc to get answered questions list against user.

DynamoDB Update Item

Could someone please give some basic code on how to update items? I am using it an have an app that needs to add/delete values to list and map properties on table items without completely deleting the value. I also have a number property that I need to use as counter. In AWS documentation it simply states to re-save the entire object. I know it is possible to update items in this manner however I cannot seem to find any code. My app is in objective c however this seems like a problem for many people using many languages so this may be a great place to answer this for any and all languages. Thanks.

android ListView not getting updated after a modification to it's cursorLoader

I am new to android and java and working on an app that has a few remaining problems that I haven't resolved yet.
I have a main activity that is a viewPager, with each page being a fragment. If the 4 fragments 3 are extended from ListFragments and one from PreferencesFragment.
The ListFragments have CursorAdapters to get data to and from SQLite databases through providers.
I am able to get data into the database, insert, modify and query the data correctly and fill the list views ok.
My preference setting are to choose different ways of viewing the data in the database.
Not knowing how to do this, I have implemented a process where I modify the cursorLoader query to the provider with a number of different choices of the "WHERE" clause. I have worked out the logic for the preferences as they exist now, implemented the code but had some difficulty finding what to try to trigger the refresh of the ListView.
Since the "dataset" hasn't really changed, no trigger can come from there, plus that would just use the same cursor as it currently exists to run the query again and return the same results (or be smart enough to know that it doesn't need to run).
On Stack Overflow I did find a couple of references to a similar implementation that suggested reStarting the cursor loader, which would then on the reStart read the current values in the stored Preferences file, create a now modified WHERE clause that will show the sub-set of data as specified in the preference settings.
In testing the app now, even with the reStart of the cursorLoader, the ListView isn't getting refreshed.
The only time I can get it to work right is restarting the app. If I stop the app and restart it, the new values are used and the ListView presents as the preferences dictate.
In looking through Stack Overflow and the Android site, I did find another set of APIs that might have been a more natural fit for what I am trying to do, namely the Filter APIs.
First question then would be, did I go in the wrong direction on how to control the "filtered" view of the datbase. Is filtering a better approach and a recommended way of
doing what I am trying to do?
Second question would be related to the fragment lifecycle of my ListFragments to achieve this CursorLoader update.
Thanks for any input on the topic.
-Dan
Found my problem here.
Two things, the way I am trying filtering is working and from what I have seen in the
Android development site, a reference there indicated that the filtering capability is
already implemented in the CursorAdapter, CursorLoader classes I am using.
When my preference settings changed, I did a reStart of the cursorLoader, but had restarted the wrong one.
Problem solved. Any input on is there a better way would be appreciated.
Regards, Dan

Using a collection that already exists in Meteor

How do you access a Meteor collection that already exists? It's easy enough when you have created the collection in the session because you have a variable that references it, but you can't access a collection by name.
What happens if for example you want to retrieve documents from an existing collection in a new session where it is not being created for the first time. I have tried to 're-create' it hoping that it would just assign the existing collection to the new variable name (seeing that I can't find it by name), but it just throws an error to tell you that the collection already exists.
I've got some externally generated collections that I'm accessing via meteor. I'm not 100% sure that this will answer your question, but I hope it'll at least help.
One gotcha (doesn't apply to you it sounds like, here for completeness) is that if your collection was not created by Meteor, you'll need to export an environment variable to point Meteor to your DB.
For example, if the following env. variable is exported in the shell:
MONGO_URL=mongodb://localhost:3002/foo
...and then you invoke the meteor application, it'll point to the db "foo" in MongoDb, at which point you simply defined your collections as #Akshat mentions above in his comment:
collection = new Meteor.Collection("fooCollection") // this lives inside the foo DB.
If you're dealing with collections that have already been created by Meteor, by default they'll be inside the meteor db, eg:
MONGO_URL=mongodb://localhost:3002/meteor
...and you should be able to simply hook into them the same way; by simply declaring your collection and using it as you would. No need to create, obviously.
It sounds like you're already doing this but for other newcomers like me: in cases like this it's really handy to use the console in Chrome, Firefox, etc. and do some inserts that way - you'll see where your data lands, or you'll see other good bits of information that will help you home in on the issue - console.log() has saved my bacon a couple of times.
At any rate, it's worth validating exactly where the Meteor app is pointing vs. where you think it's pointing. Your collections should be accessible and should Just Work...

Asp.net - Trouble with updating LINQ Classes

We just created a new field in a database table, and so deleted, and re-inserted the table in the LINQ Class. The new database field appears in the LINQ Class in the diagram. However, when we're using the field, we get an error that says the table does not contain a definition for the field.
Any ideas on how we can solve this? Thanks!
UPDATE: What steps are required to update the LINQ to SQL Class? Maybe we're doing something wrong.
UPDATE 2: Picture of our problem - LINQ - http://img99.imageshack.us/img99/6033/usertable.png | Code - http://img43.imageshack.us/img43/5145/linqerror.png
Check the table def side of your mapping documents, either using properties in the designer, or by closing Studio and examining the XML. I recommend the designer.
Make sure the field name matches the field name in the database.
I've had problems with a few reserved keywords when using Linq2Entities, and I'd recommend you avoid reserved words in names (even though the [] handle them).
While this doesn't answer your question necessary, it may help to solve it - I've been a long time fan of the LINQ to SQL and Entities tools by Huagati. The re-sync aspect alone has saved me so much time, it's well worth the $50 (for the standard version) IMO.
http://www.huagati.com/dbmltools/
Hope it helps...
Edit:
In order to update the LINQ to SQL classes, you can either do it manually (bllurgh) or, you can remove them from the designer and drag-and-drop them from the Data Connections node in the Server Explorer.
I had to delete the entire LINQ Class, recreate it and re-add the tables for my problem to go away. Simply deleting a single table and re-adding it, or deleting all tables in the class and re-adding them did not work either.
I was having exactly the same issue, but I found that deleting the problematic tables in the Object Relational Designer and re-adding them (and re-adding the associations as well) solved the issue. I did not have to delete the entire DataContext, nor did I have to delete any of the tables that were still working properly. I would recommend trying this first before doing anything more drastic.

Resources