Questions tagged [upsert]

UPSERT is a combination of UPDATE and INSERT, typically used in relational databases.

UPSERT refers to types of statements (usually database statements) that INSERT an item (record) to a resource (table in a database) where, if the item already exists, it will update the existing item with the fields provided. The term UPSERT is an amalgamation of UPDATE and INSERT and is common slang among database developers.

1227 questions
0
votes
0 answers

MongoDB positional upsert, update callbacks

I have following structure in my collection: { "_id" : { "id_1" : "1", "id_2" : "1", "version" : "2.0" }, "value" : [ { "date" : ISODate("2014-10-01T00:00:00.000Z"), …
0
votes
2 answers

Override existing Docs in production MongoDB

I have recently changed one of my fields from object to array of objects. In my production I have only 14 documents with this field, so I decided to change those fields. Is there any best practices to do that? As it is in my production I need to do…
user555
  • 1,489
  • 2
  • 15
  • 28
0
votes
1 answer

UPDATE on duplicate columns when three are duplicate but not just one

I'm implementing a MySQL database that uses an x/y/z primary key structure, where x and y are foreign keys and z is a local key. My predicament is that I don't want a duplicate case to be activated unless all three are duplicated. Assuming I have…
TheBat
  • 1,006
  • 7
  • 25
0
votes
2 answers

Meteor.js + Mongo: How can I write to my Mongo collection from an external process?

I have a Meteor app running on Heroku with a Mongo database addon through Compose (previously MongoHQ). I would like to insert documents into this database from an entirely different app (Python/Django, not Meteor). So I installed pymongo into my…
tadasajon
  • 14,276
  • 29
  • 92
  • 144
0
votes
2 answers

php postgresql check if record already before inserting

I cannot figure out the proper wording/syntax for the query statement. I want to check if there is a school already in our table (names schools) that matches the school name. If so, the state it already exists. Any input would be great! //create a…
Shmoo13
  • 1
  • 1
0
votes
2 answers

add if no duplicate in collection mongodb python

i'm writing a script that puts a large number of xml files into mongodb, thus when i execute the script multiple times the same object is added many times to the same collection. I checked out for a way to stop this behavior by checkinng the…
Oussama L.
  • 1,842
  • 6
  • 25
  • 31
0
votes
1 answer

Rails 4 MongoID Upsert Attempt

I've been trying for a while to find just the right command to do an upsert, but I have failed miserably. Here is what I'm trying: csv.each do |row| inner = {} if row['PN'] != 'TOTAL' time = Time.now stamp =…
Simply Seth
  • 3,246
  • 17
  • 51
  • 77
0
votes
1 answer

Index and upsert a mongo subdocument

I was working on mongo and I'd like to do the following things: when a set of (lat, lon, uid) comes in: 1. the collection has lat as unique index, also for each lat the lon index is unique 2. if (lat, lon) pair exists in this collection, update uid…
Shih-Min Lee
  • 9,350
  • 7
  • 37
  • 67
0
votes
1 answer

MERGE in SQL Server

I am trying to perform the following using a MERGE statement I have a table that has two columns (TagId is an Identity (PK) and Name as a VARCHAR). I would like to check first if Name exists before I insert it. If it does exist, I would like to get…
Sam
  • 875
  • 10
  • 22
0
votes
2 answers

Mongoose specifying an _id on upsert (Query)

In my chat application, every user has a dictionary of unread messages which looks like this : Unread Dictionary { _id: // reference to their user_id, events: [] // array of ObjectIds } I want to make a mongoose findByIdAndUpdate query…
Jorge Olivero
  • 3,705
  • 9
  • 27
  • 33
0
votes
1 answer

mongodb c++ driver does not upsert

In mongodb, I have this doc: { "_id" : ObjectId("53e157918b3354f7157142d2"), "packet" : [ { "datetime" : ISODate("2014-08-05T16:16:46.337Z"), "signallingType" : "M2PA", "clgNum" : "", "cldNum" : "", "opc"…
David Villasmil
  • 395
  • 2
  • 19
0
votes
1 answer

Assign update query value to variable in SQL

I need to insert some rows to tables in PostgreSQL. But before inserting the row into table, I should check whether the record is existing or not by using update statement. If update statement returns 0 rows, then I can insert, otherwise I can skip…
Balakrishna
  • 166
  • 2
  • 13
0
votes
1 answer

PostgreSQL replace table between databases

On a website I have some scripts which work on a temporary database. Before the scripts are starting I drop and recreate the temporary database from the production database. On the end of the process I would like to update the production database…
lw_lewy
  • 15
  • 4
0
votes
1 answer

Code Generation of an Upsert / Merge for SQL Server - C#/.NET

What is the best way to generate an "UPSERT" Merge statement for SQL Server? I'm looking for a way to just put in a SQL Server connection string and then point a piece of code at a single SQL Server table. Is it to crawl INFORMATION_SCHEMA.COLUMNS…
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
0
votes
1 answer

MongoDB upsert - subarray wont add subarray

static::db()->resetError(); $wherehash = array("hashtag" => $hashtag[$j]); $hash->update($wherehash,array("hashtag" => $hashtag[$j],"lastused"=>new MongoDate(), "stats" => array(array("statusId"=>new MongoId($status['_id']),"timestamp"=>new…
RussellHarrower
  • 6,470
  • 21
  • 102
  • 204