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 7838661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:10:21+00:00 2026-06-02T15:10:21+00:00

On Facebook statues, you can start typing an @ and tag a user in

  • 0

On Facebook statues, you can start typing an @ and tag a user in a status. This question is not about the frontend, but rather how to store the data for that feature. What is the best way to achieve this functionality in a generic way for representing any mongodb entity in a string in a dynamic way. The goal being if the entity changes, it representation in the stored string also changes. For example one idea I had was this:

Post: {
    _id: "48ajsdlfhsdjfkjsljsd"
    name: "Post One",
    text: "@user is the best for liking @thing, and @thing"
    tags: [user:1234, thing:456, thing:789]
}

So I would load this post, then look at the tags, load the models for each tag type and id, then rewrite the string to be: “Chris is the best for liking StackOverflow, and Mongo”. This seems inefficient, any better ideas?

  • 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-02T15:10:22+00:00Added an answer on June 2, 2026 at 3:10 pm

    Your answer works Geoff, but I was looking for something a little more efficient. What I have done is store a document in Mongo like this

    {
        _id: "4bdslakjghjdgkjsh123",
        title: "Post One",
        text: "@ is cool for liking @",
        tags: ["user:4bcasdkasd89", "product:4basfkjafkjlfl"]
    }
    

    And the code to translate the tags is run after loading a message. It basically uses the tag to know which type of model to use, and the id to load it. Then it creates an array of values using the as_tag method of a model, or to_s. This array is then substituted into the original string in order replacing the @ signs. A lot like sprintf. So it translates to “Chris is cool for liking bicycles”

    def after_initialize
        tags = self.collect_tags
        tags.each do |value|
          self.text.sub!(/@/, value)
        end
    end
    
    def collect_tags
        self.tags.collect do |tag|
            model, id = tag.split(':')
            model[0] = model[0,1].upcase
            m = Models.const_get(model).find(id)
            if(m.respond_to? 'as_tag')
                m.as_tag
            else
                m.to_s
            end
        end
    end
    

    Any way to improve the efficiency here?

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

Sidebar

Related Questions

If you press @ when typing a status on facebook.com, you can type a
I'm getting this exception from facebook SDK: Fatal error: Uncaught OAuthException: (#506) Duplicate status
Facebook API can give the pages a user admins. Suppose that it returns me
Facebook's status update input (well, contenteditable div) detects links. When typing a link it
From what I can read om Facebook Dev Docs this is how I add
Hey, sorry to bother you again, but I can't get this to work and
Want to find out if facebook status can be updated through flex or air.
I've created a Facebook/Twitter like status update and can add the new status to
This question has been asked before on SO, but most of those questions were
How I can update status for my facebook page from other site from javascript.Please

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.