Update Statement

21 views
Skip to first unread message

Matt Bodenheimer

unread,
Apr 21, 2016, 3:00:01 PM4/21/16
to mongodb-user
Gents still learning Mongo as I am moving from T-SQL, I am using MongoChef as of now which I really love.

here is what I am trying to do....

CURRENTLY I AM DOING THE FOLLOWING
I have a collection called playerstats.

1) I need to run the following query to make sure I get the correct records. 
{ "player.status": "ACTIVE", "game.league.abbreviation": "MLB", $and: [ { "game.gameDate": { $gt: "2016-04-21T06:00:00.000Z" } }, { "game.gameDate": { $lt: "2016-04-22T05:00:00.000Z" } } ] }

2) Now that I have the records I need to change (Roughly 750). I export to a CSV (ALL 382 Fields)

3) In excel I Index Match to update 1 value (salary). I then export the file back out to CSV.

4) In Mongo Chef I click import and import the records back in based on objectid. 

5) It does a pretty good job linking up types, but there are still several (30 or so) Fields I need to change the type to, and still cant change an old empty to an array, I have to leave it as a string. 


Please help me find another way :(


In t-sql I would run one huge group of updates at one time???

Thanks

Matt

Kevin Adistambha

unread,
Apr 29, 2016, 1:39:49 AM4/29/16
to mongodb-user

Hi Matt,

I’m not sure I fully understand your use case yet. It seems to me that you:

  1. perform a query to select some documents that you need to update
  2. export those matching documents to CSV
  3. perform the modification on Excel
  4. then re-import those records back to MongoDB

Is my understanding correct?

If this is correct, you might be better served by performing the updates using a db.collection.update() directly in the database. Performing the updates using a separate tool which also involves exporting and re-importing data may not conserve the BSON datatypes (which is how the documents are stored in MongoDB), as you may have found.

Some information that may help:

If you’re still having difficulties with this issue, could you please provide:

  • The MongoDB version you’re using
  • An example document you need to update
  • What you need to update (i.e. how you expect the documents should look after being updated)

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages