upsert

MongoDB: update dictionary in document

橙三吉。 提交于 2019-12-22 05:05:29
问题 I have a MongoDB document that saves occurrences of some things in a dictionary: { "id" : 1, "occurrences" : { "1" : 1, "2" : 5, "17" : 1, "35" : 4 } } I now want to add or update some entries, for example add a "12:3" to the occurrences, or update the number of occurrences of "17" to 2, so let's say as an example I want to add {"12":3} and {"17":2} to this dictionary. It is driving me crazy because I simply can not get it to work. I could use arrays and all that, but I would really like to

MongoDB: Update/Upsert vs Insert

怎甘沉沦 提交于 2019-12-21 06:59:38
问题 Recently I notice a huge performance difference between doing multiple upserts (via bulk operations) vs an insert (multiple documents). I would like to know if I am correctly on this: Upsert/Updates will be like a find() and update() so it does 2 things read and write Insert will just write so its a lot faster Thus the performance difference? If this is the case, I wonder if I need a lot of writes regularly, instead of updating a document, I write a new document with a createdOn field. Then

Postgres 9.5+: UPSERT to return the count of updated and inserted rows

荒凉一梦 提交于 2019-12-20 18:09:32
问题 I get the canonical example: INSERT INTO user_logins (username, logins) VALUES ('Naomi',1),('James',1) ON CONFLICT (username) DO UPDATE SET logins = user_logins.logins + EXCLUDED.logins; But now I also need to know: How many rows were inserted How many rows were updated because existing How many rows could not be inserted because of constraints If the constraint is not respected for the last row, will the previous inserted/updated rows be persisted in the DB? 回答1: I do not know how else you

Entity Framework - UPSERT on unique indexes

走远了吗. 提交于 2019-12-20 17:28:01
问题 I searched a bit regarding my problem but can't find anything that really to help. So my problem/dilema stays like this: I know that mysql database have a unique index system that can be used for insert/update in same query using this format: insert into t(a,b,c) values(1,1,1) on duplicate keys update b=values(b),c=values(c); and a replace format used to replace a existing recording by that index. to be honest the only similar stuff that I saw in MSSQL is the merge but I really don't like it

Entity Framework - UPSERT on unique indexes

时间秒杀一切 提交于 2019-12-20 17:27:26
问题 I searched a bit regarding my problem but can't find anything that really to help. So my problem/dilema stays like this: I know that mysql database have a unique index system that can be used for insert/update in same query using this format: insert into t(a,b,c) values(1,1,1) on duplicate keys update b=values(b),c=values(c); and a replace format used to replace a existing recording by that index. to be honest the only similar stuff that I saw in MSSQL is the merge but I really don't like it

INSERT or SELECT strategy to always return a row?

被刻印的时光 ゝ 提交于 2019-12-20 03:52:31
问题 Using Postgres 9.6, I have followed the strategy recommended in https://stackoverflow.com/a/40325406/435563 to do an INSERT or SELECT and return the resulting id: with ins as ( insert into prop (prop_type, norm, hash, symbols) values ( $1, $2, $3, $4 ) on conflict (hash) do update set prop_type = 'jargon' where false returning id) select id from ins union all select id from prop where hash = $3 However, sometimes this returns nothing. I would have expected it to return a row no matter what.

SQL standard UPSERT call

你说的曾经没有我的故事 提交于 2019-12-19 05:57:13
问题 I'm looking for a standard SQL " UPSERT " statement. A one call for insert and update if exists. I'm looking for a working, efficient and cross platform call. I've seen MERGE , UPSERT , REPLACE , INSERT .. ON DUPLICATE UPDATE but no statement meets the needs. BTW I use MYSQL and HSQLDB for unitests. I understand that HSQLDB is limited and may not cover what I need, but I couldn't find a standard way even without it. A statement that only MYSQL and HSQLDB will also be enough for now. I've been

MongoDb upsert exception invalid BSON field

限于喜欢 提交于 2019-12-19 02:59:12
问题 This exception: Exception in thread "Thread-1" java.lang.IllegalArgumentException: Invalid BSON field name id at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:516) at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:188) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131) at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45) at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63) at org.bson.codecs

How can I use use Entity Framework to do a MERGE when I don't know if the record exists?

让人想犯罪 __ 提交于 2019-12-18 10:48:18
问题 In this SO answer about Entity Framework and MERGE, the example for how to code it is this: public void SaveOrUpdate(MyEntity entity) { if (entity.Id == 0) { context.MyEntities.AddObject(entity); } else { context.MyEntities.Attach(entity); context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); } } This assumes that you already know if the entity that you want to upsert exists or not; in this case you check entity.Id . But what if you don't know if the item exists or not?

PostgreSQL INSERT ON CONFLICT UPDATE (upsert) use all excluded values

笑着哭i 提交于 2019-12-18 10:12:14
问题 When you are upserting a row (PostgreSQL >= 9.5), and you want the possible INSERT to be exactly the same as the possible UPDATE, you can write it like this: INSERT INTO tablename (id, username, password, level, email) VALUES (1, 'John', 'qwerty', 5, 'john@mail.com') ON CONFLICT (id) DO UPDATE SET id=EXCLUDED.id, username=EXCLUDED.username, password=EXCLUDED.password, level=EXCLUDED.level,email=EXCLUDED.email Is there a shorter way? To just say: use all the EXCLUDE values. In SQLite I used to