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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:50:34+00:00 2026-06-16T01:50:34+00:00

I am trying to cache friends from social media in the user’s doc and

  • 0

I am trying to cache friends from social media in the user’s doc and am having issues storing/getting them back.
First, I blindly strip the their friends cache and would just fill it with my fresh fetch of the data, but through that I found out that the embedded Documents must be unique among all the users (I have a couple of friends that are the same in my test accounts and I get:

{"name":"MongoError","err":"E11000 duplicate key error index: test-dev.users.$friends.outsideID_1  dup key: { : \"1205314313242\" }","code":11001,"n":0,"connectionId":274,"ok":1} 

so from this I know that because that embedded document exists in my other already registered and updated account it can’t create that document (outsideID is index because I plan on searching using it later))
So then I started trying to OutsideFriend.find({‘outsideID’:{$in:friendsIDs}}(where friendsIDs is an array of the ids I got from the SM query), etc.. and then in the callback I go through and try added the new friends and just add the existing docs to the user in question so that it’s not trying to duplicate it in the system. However, for whatever reason OutsideFrind.find() never returns any docs… which makes me think that the embedded docs aren’t centralized… but then why would the first attempt fail?

How am I supposed to do this? (schema below, please let me know if you need any other info!)

current schema:

//External friend model                                                                                                                                                                                              
var OutsideFriend = new Schema({
         outsideID:{type:String, index:true, unique:true}
        ,username:String
        ,location:String
        ,avatarURL:String
});

//User model                                                                                                                                                                                                         
var User = new Schema({
        avatarURL:String
       ,mySMID:String
    //Social Media info                                                                                                                                                                                                   
        ,smID:{type:String, index:true, unique:true}
        ,tok:String
        ,tokSec:String
        ,friends:[OutsideFriend]
};
  • 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-16T01:50:36+00:00Added an answer on June 16, 2026 at 1:50 am

    There’s a lot going on in your question, but if you want to query OutsideFriend independent of User, then you shouldn’t be embedding them in the User model. Instead, just store ObjectId references to the friends and then populate that in User when you need the full details. Don’t prematurely optimize with embedded copies unless you find you need to as that introduces consistency challenges.

    So your User model would change to:

    var User = new Schema({
        avatarURL:String
        //Social Media info
        ,smID:{type:String, index:true, unique:true}
        ,tok:String
        ,tokSec:String
        ,friends:[{type: ObjectId, ref: 'OutsideFriend'}]
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to cache results from several pages that do heavy database processing. These
I'm trying to cache the user timeline of a Twitter feed using Zend_Service_Twitter which
I'm trying to cache user controls and on some pages i want to cache
I have some code(client side) that is trying to cache responses from a web
I'm trying to cache some results retrieved from database using Yii framework 1.1.12. Here
I'm trying to cache some information that I've retrieved from a database. I've decided
I'm trying to cache images I load from Flickr. If I load the same
I'm trying to cache some images loaded from a URL by using AFImageCache, without
I'm trying to loop results from a php script into my jquery friends list.
I am trying to cache these images using this code... But i keep getting

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.