Midwest Dev Chat

MidwestDevChat.com

  • The newest 15 messages in the super-cool #database channel.

  • 07/15 16:50:41 Rolando: does anyone know if there is a way in mongodb to reference the found document in an update query? `db.test.update({foo: "bars"}, {$push: {history: {$each: [ this ], $slice: 3}}})` something like this. if a document is found and is updated, the current revision of the document will be pushed onto the `history` key and is limited to 3 revisions but `this` resolves to some crazy huge object that has seemingly nothing to do with the document that was found and `$$ROOT` doesn't work in this case for some reason
  • 07/15 18:34:13 Roselyn: @Rolando I know absolutely nothing about Mongo... but Im always down for a good time. laughing Can you try to sort and grab the last modified row? ( https://stackoverflow.com/questions/4421207/how... ) In SQLite/MySQL/etc, you can grab the last modified row's ID after the operation is complete but Im not for sure on a NoSQL db how you would approach that!
  • 07/15 19:52:15 Roselyn: Also not 100% sure why your referencing the last item updated but you might be able to get a response on how many rows were updated when the transaction is completed
  • 07/15 19:54:29 Roselyn: Also also laughing .. I noticed you dont have multi set to true, so your updating a single item. So the last item updated would be your update statement..no?
  • 07/16 20:25:12 Kathern: Huh. PostgreSQL json manipulation syntax is fascinating.
    ...
    jhannah=# select * from candidate;
                    details
    ---------------------------------------
     {"name":"jay"}
     {"contributions": null}
     {"name":"jay2","contributions":"TBD"}
    (3 rows)
    
    jhannah=# UPDATE candidate
    SET details = detailsjsonb - 'contributions' || '{"contributions":null}'
    WHERE details->>'contributions'='TBD';
    UPDATE 1
    jhannah=# select * from candidate;
                       details
    -----------------------------------------
     {"name":"jay"}
     {"contributions": null}
     {"name": "jay2", "contributions": null}
    (3 rows)
  • 07/16 20:28:53 Kathern: `- 'contributions'` is a surprising (to me) syntax for what this apparently does slightly_smiling_face
  • 07/16 20:29:17 Kathern: and `details->>'contributions'='TBD'` is just wacky
  • 07/16 20:51:31 Roselyn: Must not have the proper privileges...To Be Disclosed...rolling_on_the_floor_laughingrolling_on_the_floor_laughing
  • 07/16 21:02:21 Roselyn: Bah! I got it! Totally Bullshit Deafferret!
  • 07/16 23:39:01 Man: I generally write that WHERE clause as
    details @> '{"contributions":"TBD"}'
    
    because you can take advantage of a GIN index
  • 07/17 11:10:51 Kathern: ooo thanks @Man
  • *Usernames have been changed to protect the innocent.
We're currently 1184 members strong. Join us!
Request Invite

Check out all the cool channels!

Join the conversation!