Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:59:14+00:00 2026-06-12T21:59:14+00:00

My database will not update my active_quests. All I am trying to do is

  • 0

My database will not update my active_quests. All I am trying to do is replace one array of hashes with another, updated array of hashes. I assumed would be the simplest way of handling this. Here’s the code:

# construct the query
query = Player.where( :_id => player_id).fields( :xp, :lvl_prgrssns, :active_quests, :completed_quests )

# get the player
player = query.first

if !player.nil?
    return_val = player.set( :active_quests => [{"quest_id" => "123"}, {"quest_id" => "456"}])
    logger.debug "return_val = "+return_val.to_s # comes out as 180
end

My understanding is that, if the return from a set is positive, that means that the set was successful. It returns as 180 in this simplified case but the active_quests never get updated on the player. I can go into the mongo console and execute this:

db.players.update({_id:ObjectId("50756b1896f4f5121a00000a")}, {$set:{active_quests:[{"quest_id":"1"}, {"quest_id":"2"}] }});

and active_quests will update as expected but no matter what I try in rails the update appears to go through but nothing updates.

Here are some of the many alternatives I have tried (all have been tried with and without .to_mongo and with and without player.save after them):

Player.where( :_id => params[:player_id] ).update(:active_quests => active_quests_list.to_mongo)

player.update_attributes(:active_quests => active_quests_list.to_mongo)

player_update = player.as_json
player_update["active_quests"] = active_quests_list
player.update_attributes(player_update)

return_val = query.update( "$set" => {:active_quests => player.active_quests.to_mongo} )

return_val = query.update( {:_id => params[:player_id]}, {"$set" => {:active_quests => active_quests_list.to_mongo}})

I’m hoping someone here might know what I am doing wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:59:15+00:00Added an answer on June 12, 2026 at 9:59 pm

    After further investigation, it turns out that this was a problem relating to how the player variable was being updated outside of the function.

    The following lines will update the record in this case (both in-memory and in the database)

    player[:active_quests] << @active_quests_list
    player.push_all(:active_quests => player.active_quests)
    

    However, the player variable was local to this function in this case, and was being updated again after the function returned.

    This was only discovered after careful examination of the output of “mongod -vvvvv”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Obviously, changes in a database will not reflect what is in an index all
I have a SQL Server 2000 database that will not display the column list
I have a large database which will only be updated once a year. Every
I have a MySQL database, and a particular table in that database will need
Occasionally in our lab, our postgres 8.3 database will get orphaned from the pid
I'm designing a database which will store information about some artists. These artists can
I am creating a database that will help keep track of which employees have
We have a new filestream database that will be initially loaded with 65GB data,
I have to design a database which will allow me store data in multiple
I am working on the design of a database that will be used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.