upsert

Updating the path 'x' would create a conflict at 'x'

风格不统一 提交于 2019-12-09 02:15:21
问题 This error happens when I tried to update upsert item: Updating the path 'x' would create a conflict at 'x' 回答1: Field should appear either in $set , or in $setOnInsert . Not in both. 回答2: If you pass the same key in $set and in $unset when updating an item, you will get that error. For example: const body = { _id: '47b82d36f33ad21b90' name: 'John', lastName: 'Smith' } MyModel.findByIdAndUpdate(body._id, { $set: body, $unset: {name: 1}}) // Updating the path 'name' would create a conflict at

Mongodb upsert throwing DuplicateKeyException

筅森魡賤 提交于 2019-12-08 16:25:48
问题 I do get this error [2] from time to time when attempting to upsert (increment or insert) a document using method [1]. [1] public NGram save(final NGram ngram) { Criteria cr = where("_id").is(ngram.getNgram()) .and("f3c").is(ngram.getF3c()) .and("tokCount").is(ngram.getTokCount()) .and("first").is(ngram.getFirst()) ; if( ngram.getTokCount() > 1 ) { cr.and("second").is(ngram.getSecond()); } if( ngram.getTokCount() > 2 ) { cr.and("third").is(ngram.getThird()); } final Query qry = new Query( cr

How to do upsert using jongo?

那年仲夏 提交于 2019-12-08 15:14:35
I have a users table/collection and would like to upsert a user - update a user if exists or add a new one if still not exists. Structure below. By "exists", I mean having some external ID. In this case, googleId . How can I do it using Jongo library? Thanks. public class User { public String _id; public String email; public String givenName; public String familyName; public String googleId; } Considering having a user with an already loaded googleId (passed google auth), and I'd like to upsert it to mongoDB, using Jongo: // Init MongoClient mongoClient = new MongoClient("localhost", 27017);

Dynamic upsert in postgresql

本小妞迷上赌 提交于 2019-12-08 13:52:25
问题 I have this upsert function that allows me to modify the fill_rate column of a row. CREATE FUNCTION upsert_fillrate_alarming(integer, boolean) RETURNS VOID AS ' DECLARE num ALIAS FOR $1; dat ALIAS FOR $2; BEGIN LOOP -- First try to update. UPDATE alarming SET fill_rate = dat WHERE equipid = num; IF FOUND THEN RETURN; END IF; -- Since its not there we try to insert the key -- Notice if we had a concurent key insertion we would error BEGIN INSERT INTO alarming (equipid, fill_rate) VALUES (num,

Insert if not exists else update it in Netezza

帅比萌擦擦* 提交于 2019-12-08 08:07:44
问题 I am having issue using if not exists statement in Netezza. I am trying to check if record is not there first then insert else update the record. I could not find a better way to do this in Netezza. Here is what I have but does not work: IF NOT EXISTS(SELECT ID FROM OLD_TABLE WHERE ID NOT IN (SELECT ID FROM NEW TABLE ) ) INSERT INTO NEW_TABLE (NAME, LOCATION) ELSE UPDATE NEW_TABLE SET NAME = X.NAME FROM (SELECT NAME, LOCATION FROM OLD_TABLE)AS X WHERE X.NAME = NEW_TABLE.NAME 回答1: Assuming you

Upsert with $in

喜你入骨 提交于 2019-12-07 19:12:14
问题 I want following functionality in MongoDB. I have a collection named 'entities', which basically stores entity text and it's count. The collection looks like this: [{u'_id': u'facebook', u'n': 120}, {u'_id': u'florida', u'n': 98}, {u'_id': u'vegas', u'n': 94}, {u'_id': u'andrew_mason', u'n': 93}, {u'_id': u'obama', u'n': 85}, {u'_id': u'twitter', u'n': 81}, {u'_id': u'outlook', u'n': 81}, {u'_id': u'delhi', u'n': 75}, {u'_id': u'google', u'n': 74}, {u'_id': u'virginia', u'n': 71}] Now, I want

Mongoimport to merge/upsert fields

◇◆丶佛笑我妖孽 提交于 2019-12-07 14:39:30
问题 I'm trying to import and merge multiple CSVs into mongo, however documents are getting replaced rather than merged. For example, if I have one.csv: key1, first column, second column and two.csv: key1, third column I would like to end up with: key1, first column, second column, third column But instead I'm getting: key1,third column Currently I'm using: mongoimport.exe --ftype csv --file first.csv --fields key,firstColumn,secondColumn mongoimport.exe --ftype csv --file second.csv --fields key

How do I do batch upserts in SQL Server?

女生的网名这么多〃 提交于 2019-12-07 14:28:07
问题 I'm using the MERGE statement to upsert rows in an sql server 2008 database. However, my sproc is a single-row operation, whereas in fact I'd prefer to batch these. Is this even possible and, if so, how do I do it? 回答1: Can you use Table-Valued Parameters in your proc? Take a look here http://www.sommarskog.se/arrays-in-sql-2008.html#TVP_in_TSQL to get some ideas Then in the proc you can use MERGE against the TVP 回答2: i have created a proc called 'upsert' which takes a source table name,

Oracle Merge. How can I use it?

不问归期 提交于 2019-12-07 05:19:37
问题 I have this function: Procedure UpdateDefaultWeight ( vYear Number, costWeight Number, qualityWeight Number, serviceWeight Number ) AS type weight_table is table of Number(5,2) index by varchar2(50); weightArray weight_table; currentPosition varchar2(50); Begin weightArray('Cost Weighting') := costWeight; weightArray('Quality Weighting') := qualityWeight; weightArray('Service Weighting') := serviceWeight; currentPosition := weightArray.first; Loop Exit When currentPosition is null; Insert

Mysql on duplicate key update + sub query

我们两清 提交于 2019-12-07 05:17:08
问题 Using the answer from this question: Need MySQL INSERT - SELECT query for tables with millions of records new_table * date * record_id (pk) * data_field INSERT INTO new_table (date,record_id,data_field) SELECT date, record_id, data_field FROM old_table ON DUPLICATE KEY UPDATE date=old_table.data, data_field=old_table.data_field; I need this to work with a group by and join.. so to edit: INSERT INTO new_table (date,record_id,data_field,value) SELECT date, record_id, data_field, SUM(other_table