keep the size of array in a document less than or equal to 9 - google-cloud-firestore

I am using Firestore and have users documents with images array. I am able to add / delete images from the images array without any problem. Both add and delete operations to the array are considered update to the user document. I would like to have an update security rule such that I can't have more than 9 images.
I am using the following rule:
allow update: if resource.data.images.size() < 9
As soon as I have nine images in the array, I am no longer able to delete an image. So the rule is conflicting for add and remove. What is the best way to handle this. I appreciate any help.
Thanks

resource.data contains the fields in the document that currently exist. request.resource.data contains the fields that are about to be written by the client app. You will want to use the latter to check the incoming fields rather than the existing fields.
allow update: if request.resource.data.images.size() < 9

Related

Query large list of metadate in weaviate

I have 100.000 images, each of them have 500 orb vectors, and each image has a unique tag.
My general issue is, when I insert a new image (i.e. 500 new vectors), how can I know if the image's tag is already in the database ?
What I do is to attache to each vector a metadata "tag". In can retrieve the inserted tags with
result = client.query.get('orb_vector', ['tag'])\
.with_limit(200)\
.do()
This provides more or less 200 tags among the 100.000 existing.
Accordingly to the documentation, that way of doing is not scalable.
How do I do ?
Context:
My database is not very dynamic; apart of the initial big insertion (100.000+ images), there will be few insertions each day. So I'm okay with a request taking 5 minutes and keeping the result in memory in a non-dynamic way. Plain python list is okay.
Clarification: each image has one tag, but 500 vectors. So each tag is present 500 times in the database.
I'm using python.
What I can do:
Writing the list of tags in a json/mongo/other and reading/updating it each time I insert new images.
I prefer to avoid this solution since the synchronization between the weaviate database and the json will just be a nightmare.
Have you considered creating a separate class for the tags and using query filters?
For example, define a schema for a class named Tag where:
it has a property called "name" to store the tag's name e.g. outdoors, indoors, etc
it has a property called "images" to store the cross references to the images that are tagged with "outdoors".
Then, when you want to insert an image with tag "car", for example, you do a WHERE filter on the Tag class where the name name is Equal to "car".
If the result is empty, then that tag does not exist.

Embedded view ( subform ) and form - LOTUS NOTES

I have a main form called fm_Main. This fm_Main contains an embedded view which has 2 actions: Add & Delete. When I click Add is opening another form called fm_Second and here I can add some fields which will be displayed on the embedded_view on fm_Main.
The problem is: Let say I have 3 documents. All of them contains an empty embedded view. If I add some value fields in one document into the embedded view and then I save that document, all the 3 documents contains that values into the embedded. It should be: just one of them should cotain because I modified only one, the 2 of them shoudn't have that values displayed in the embedded view. Thank you!
PS: Also if I saved one document with an entry into the embedded view. When I want to create another new document, in the embedded view there exists the last entry from the last document. I want to be empty!
You must filter the embedded view to only show the entries related to the currently open main document.
Most programmers would use the UniversalID of the main document, it can be automatically populated into the entries you create.
One thing to think about is that you may want to store the Universal ID in a computed when composed field on teh main document. If you get a replication error in the future, the Universal ID may change, and you will not be able to get to the entries in the embedded view.
I been doing exactly this in several large Notes databases, works perfectly fine.
Expanding on Karl-Henry's suggestion, you should make into a categorized view and use the Show Single Category feature of the embedded view. I might suggest using the #Unique function instead of the UNID to relate the Main and Second documents, but that's a matter of preference. In either case, you have to make sure that the value inherits down into a field in the Second docs, and you can use that field as the category for the view.

Sorting Entry Fields in Movable Type 5 CMS

My CMS is currently Movable Type 5.04. The attached screenshot is how I check in Compose Screen of MT CMS.
And it appears in the new entry create page with the following order.
- Location 5
- Job Description 5
- Bio 5
- Job Title 5
I would like to change the order into following.
- Job Title 5
- Location 5
- Job Description 5
- Bio 5
Is there any way to do so? I have checked in the cfg_entry.tmpl file and the above Entry fields were not there as there were custom fields. Could you please help me sort them like above?
the order of the fields are stored into the permission table, in 'permission_entry_prefs' field. (and there is a matching field for the page)
the row with blog_id 0 is the user defaults, and each blog's raw will override the default for this blog.
and the format is very simple: comma delimited list. you should find there something like "title,text,tags,assets". just reorder them for your liking.
If the user will toggle on and off fields, I'm not sure if the original order will return or not. if it does, then a simple plugin can solve it in more permanent way.
I remember doing this by recreating the custom fields in the wanted order (MT pulls them from the DB in a specific order, sorted by ID IIRC). If you have existing data, then you need to delete the fields definitions (not the data) then recreate them in the order you want changing just their numerical ID (not anything else).
I'm traveling and busy at the moment so can't dig into details. But study how CF are defined in the DB and how to simply reorder them by ID.

How to make a fake join in MongoDB?

I am developing a webapp using PHP and MongoDB. In this app I keep two collections. One to keep data about files and one to keep track about download events for each file.
I need to get the 10 latest downloaded files but I know joins is not an option. The events document only stores the file id and the other collection stores the thumbnail.
Right now I first get the 10 recently downloaded files and order it by date and the order is fine but then I use this array of files (their ids) and make a where_in query where I look for files whos id is present in the ids array. This also works fine (I get the thumbnails for the selected files) but I cannot keep the order anymore. The most recently downloaded file is not longer on top.
How can I keep the order of the ids without looping through them thus making 10 new queries instead of just one?
I cannot change the schema because I got over 40.000 documents :)
UPDATE
In short this is what I want to do:
Get all the IDs of the 10 recently downloaded files. Sorted by download timestamp.
Use this array of Ids and make a query to the files collection and get the details for each file like thumbnail, decription and so on.
The above steps works fine, BUT I cannot keep the order from the first step thus I cannot get the most recently downloaded file on top. I know I could look trought the id array and get data for each file but that would cost me 10 queries instead of one.
I don't really get your problem. Here's some pseudo-code:
// get last N download events
events = get_latest_downloads()
// retrieve associated file data
file_array = get_all_file_info_by_events(events)
display_data = []
for(e in events) {
data = find_file_info_in_the_array(file_array, e.file_id)
display_data.push(data)
}
// now display_data is contains full file info, sorted by download time.

coldfusion - bind a form to the database

I have a large table which inserts data into the database. The problem is when the user edits the table I have to:
run the query
use lots of lines like value="<cfoutput>getData.firstname#</cfoutput> in the input boxes.
Is there a way to bind the form input boxes to the database via a cfc or cfm file?
Many Thanks,
R
Query objects include the columnList, which is a comma-delimited list of returned columns.
If security and readability aren't an issue, you can always loop over this. However, it basically removes your opportunity to do things like locking certain columns, reduces your ability to do any validation, and means you either just label the form boxes with the column names or you find a way to store labels for each column.
You can then do an insert/update/whatever with them.
I don't recommend this, as it would be nearly impossible to secure, but it might get you where you are going.
If you are using CF 9 you can use the ORM (Object Relation Management) functionality (via CFCs)
as described in this online chapter
https://www.packtpub.com/sites/default/files/0249-chapter-4-ORM-Database-Interaction.pdf
(starting on page 6 of the pdf)
Take a look at <cfgrid>, it will be the easiest if you're editing table and it can fire 1 update per row.
For security against XSS, you should use <input value="#xmlFormat(getData.firstname)#">, minimize # of <cfoutput> tags. XmlFormat() not needed if you use <cfinput>.
If you are looking for an easy way to not have to specify all the column names in the insert query cfinsert will try to map all the form names you submit to the database column names.
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c78.html
This is indeed a very good question. I have no doubt that the answers given so far are helpful. I was faced with the same problem, only my table does not have that many fields though.
Per the docs EntityNew() the syntax shows that you can include the data when instantiating the object:
artistObj = entityNew("Artists",{FirstName="Tom",LastName="Ron"});
instead of having to instantiate and then add the data field by field. In my case all I had to do is:
artistObj = entityNew( "Artists", FORM );
EntitySave( artistObj );
ORMFlush();
NOTE
It does appear from your question that you may be running insert or update queries. When using ORM you do not need to do that. But I may be mistaken.