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

  • SEARCH
  • Home
  • 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 8482291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:47:13+00:00 2026-06-10T19:47:13+00:00

i’m new to MongoDB and unsure how to use the Array-Field-Type. So i created

  • 0

i’m new to MongoDB and unsure how to use the Array-Field-Type.

So i created in my model

field :admins, type: Array

in this field i wanna store all user_ids that are “admins” of the model. But when I try to set this field, it doesnt save the Information in the Array it just simple creates an String with the ID. And due to my constrain that only Admins can edit my filter function

def check_if_admin
  unless Agency.find(params[:id]).admins.include?(current_agent.id)
    flash[:notice] = "Only possible as Admin."
    redirect_to root_path
  end
end

gets the error that

"can't convert Moped::BSON::ObjectId into String"

So I tried to initiate my field with in the create def as an array with ID:

@agency.admins = [current_agent.id]

That does the Trick for one user in the Array but how do I add IDs to this field?

When I go into my Edit Form:

<%= form_for(@agency) do |f| %>
  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :admins %><br />
    <%= f.text_field :admins %>  <br />
  </div>          
  <div class="field">
    <%= f.label :agents %><br />
    <%= f.text_field :agents %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

And Type in another User_ID by hand, I’m back to my error again.
Anyone knows how to get around that?

Thanks a ton for ur help!

  • 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-10T19:47:15+00:00Added an answer on June 10, 2026 at 7:47 pm

    This message means that at some point you stored a string where there should be an ObjectId. Ruby is trying to compare current_agent.id (an ObjectId) with params[:id] (a string).

    It seems like you are not converting the input from the text_field in the form to an ObjectID before you push it onto the array.

    Take the input from the admins field and make ObjectId’s like this:

    BSON::ObjectId.new(string_representing_admin_id)
    

    I’m guessing the admins field is a comma separated array of admin _ids and that you are using some _id values that are easy to work with, like a username instead of a generated ObjectId as this would be very burdensome to work with.

    In that case you would probably split and strip the input and then make an array of the ObjectIds using a map/select.

    It would be much easier to use a select field that displayed usernames for something like this in rails right?

    Anyway, show some sample documents from the collection if you need more help.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms

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.