Mongoose How to update if exists, based on custom fields. Otherwise insert - node.js

I'm building a mongoDB database that holds sales data from multiple different systems. Each system is integrated via an node/mongoose/Express API that I'm creating for the database. Typically, you'd check the id to determine if a record already exists, and insert it if it doesn't. But since the ID from these different sources could technically overlap, I need a system to make sure that a source can only update records that originally came from that source. So I've added a column called "external_ID" where the record id from the source is saved, and another column called "integration ID", which will be unique to the specific system that sends data. But for that idea to work, I'd need to update only if those two columns matches, and otherwise insert a new record. Is that possible with MongoDB, or am I approaching this wrong?
Thank you so much.

Use upsert on update(). It will creates a new document when no document matches the query criteria.
db.collection.update(<query>, <update>, { upsert: true })
You can find more detail at Upsert Behavior documentation

Related

is it possible to update collection name dynamically in cloud firestore?

I am trying to create a collection name based on the date like i have a collection name like this Change 06-05-2020 and i want to overwrite this collection daily and make the collection name like this Change 07-05-2020 and so on is it possible to do it i ma creating the collection in this way.and basically i am trying to store the daily updated data in a particular way so i can track that information.so can i update the collection name dynamically daily?
await growthfilemsdb.collection(`Change${getISO8601Date()}`).doc(change.after.data().officeId).set(change.after.data(),{merge:false})
It's not possible to change the name of a collection. What you can do instead is simply copy all the documents from the old collection to a new one with a new name.
However, it's usually not a good idea to make the names of your collection dynamic like this. Instead, consider putting the date as a field inside the document, and using that to filter the results of queries or delete old documents.

Is their a way to set value for all existing records using Acumatica code without modifying the screen

User requirement is to create duplicate customer field in Invoice screen and that custom field is using for some historical data, But by default we are passing current Invoice customer value and later we are allowing user to change the custom field.
so in this case is there a way to set the value for existing records through code with out refreshing/modifying the existing record.
I have tried by using field level PXDefault attribute but that will not work in my case so their any events or some code to update custom field value for existing fields.
Thanks in advance.
I believe PXDefault would only execute when a new Row is being inserted. Perhaps one option could be to explicitly call cache.SetDefaultExt(e.Row) if value is null, but I am not sure whether it is 'legal' to do it on a row Selected
One other possibility is to use Generic Inquiry Mass Update (https://asiablog.acumatica.com/2016/09/mass-processing-using-gi.html). This way to could perhaps update past records in bulk. But be careful of Acumatica Transaction License limits.

Issue adding a new field to an entity in crm 2011

I am running into an issue when adding a new field to an entity. In my entity I had 526 fields, I tried to add a new one but I got the error message "Attribute xxx cannot be created because we have hit a maximum number of attributes allowed for an entity (1000)". However I only have 526 fields in the entity. Furthermore, I deleted one field I don't need anymore and I tried to add my new field but I still have the same error message even though I've deleted one field. Could anyone help me out please. I do appreciate it. Thanks !
Walloud
You will be hitting the column limit, even with only 526 fields.
You have to remember that CRM will add its own fields in addition to the ones that you have, such as ones for base currency. This can take you over the limit.
Also consider that the Filtered Views that CRM automatically creates have extra columns for lookup (name), optionset (name) and date (local) fields which can also mean you exceed the limit there.
I think your only options are to delete more fields in order to free up the room, or re-architect your entity design to split it over multiple related entities instead
Looks like you are facing the SQL Server 8k row limit
you can check the field names and verify this.
more information here:
http://mileyja.blogspot.com/2013/09/dealing-with-8k-sql-server-row-limits.html
You need to remember that some fields, such as currency will have two separate fields in SQL thus increment the column count by two for each one you create. If you have 500+ fields on a single entity then it is time to normalize the data and start breaking it out into related entities. It will be better for performance and your data in the long run.
http://en.wikipedia.org/wiki/Database_normalization
Cheers!

Solr MultiValue Fields and adding values

I am building a search engine, and have a not so unique ID for a lot of different names... So, for example, there could be an id of B0051QVF7A which would have multiple names like "Kindle" "Amazon Kindle" "Amazon Kindle 3G" "Kindle Ebook Reader" "New Kindle" etc.
The problem, and question i have, is that i am trying to enter this data from a DB of 11 ish million rows. each is being read one at a time. So i dont have all the names of each ID. I am adding new documents to the list each time.
What i am trying to find out is how do i add names to an existing Document? if i am reading documentation correctly, it seems to overwrite the whole document, not add extra info to the field... i just want to add an extra name to the document multivalue field...
I know this could cause some weird and wonderful "issues" if a name is removed (in the example above, "New Kindle" could be removed when a newer Kindle gets released) but i am thinking of recreating the index every now and again, to clear out issues like that (once a month or so. Its taking about 45min currently to create the index).
So, how do you add a value to a multivalue field in solr for an existing document?
Since according to the question linked to by #Mauricio Scheffer's comment... Solr does not currently support updating a single field value in an existing document. I see that there might be a couple of options here...
In your process that is pulling data from the database, when it finds a new name, it will need to pull all fields for the existing document from Solr, add the new value and resend the complete document to Solr (you may already be doing this).
Add some additional logic to your code that reads from the database, to gather all of the unique names for each document prior to inserting documents into the index. However, given that you have ~11 million records, there could be a resource constraint that would prevent this from being feasible.

Updating a table Access and Excel VBA

I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed in an excel sheet that is connected with MS Access database. ID is the only unique field. Sometimes, my user submits a transaction that has let's say 5 records. Then, they want to modify the submitted data in case if they entered incorrect amount and they want to correct it. I want to write a code in VBA that will do the update. my current query is:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount)
where Date=#date;
This query does not work fine because obviously it replaces all the records data with the data of the last resubmitted record because my condition is weak. My difficulty is that I can't find a good condition in the where clause that will do the update a record by record accordingly.
Please help,
You will need to use the unique id of the record, in your case the ID field to guarantee you are updating the correct record.
Something like the following:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount) where ID = "id of record you want to update"
Enjoy!

Resources