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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:41:30+00:00 2026-06-04T01:41:30+00:00

I’m dealing with a specific and simple case. I need some help, because I

  • 0

I’m dealing with a specific and simple case. I need some help, because I don’t seem to be able to find the solution for this.

I’ve created a simple Schema and Model for MongoDB inside a javascript class.

this.UserSchema = new this.Schema({
    UserId: { type: String }, 
    IsToggle: { type: Boolean}
});

this.CalendarViewUserSchema = new this.Schema({ 
    _id:  { type: this.Schema.ObjectId },
    OwnerId: { type: String },
    UserList: [ this.UserSchema ] 
});

this.CalendarViewUser = this.mongoose.model('CalendarViewUsers',this.CalendarViewUserSchema);

This is in the constructor and I already have a lot of database interactions working, but I can’t manage to get this one working.

I call this method for adding the new document:

AddCalendarViewUser : function(Id, UserToAddId){        
        NewUser = { UserId : UserToAddId, IsToggle : false };

        this.CalendarViewUser.update(
        { OwnerId : Id },
        { 
                       $set:  { OwnerId  : Id      },
           $push: { UserList : NewUser } 
                    },
        {upsert:true},
        function(err){
            if(err) {console.log(err);}
            else {console.log('Success');}
        }
    );
}, // this comma just introduces the next method.

This works fine. I can see the document is created correctly ,with Mongo Explorer, and if I use a .find() to retrieve everything from the collection, it shows up.

Then, I try to look for the inserted Doc with:

FindCalendarViewUser : function(Id){
    this.CalendarViewUser.findOne(
                { OwnerID : Id }, 
                function(err,result){

            if(err) {console.log(err);}
            else{console.log(result);}  
        }
        );
}

Here, it returns result = null.

The “Id” parameter is a String in both methods, just like the “OwnerId” in the Schema.

What am I doing wrong?

Both “OwnerId” and “Id” are the same. I also tried converting both to ObjectId, with no success.

Sorry for the code formatting.

EDIT:

Basically, I can find the Document using the _id field:

{ _id : '4fb0d1702edfda0104fc2b9f'}

But I can’t find it with the OwnerId field:

{ OwnerId : '4f55e1a6c2c7287814000001'}

These values were taken directly from the database, so they correspond to the actual stored values.

EDIT 2:

I just figured out that if I insert the value by hand:

$set:  { OwnerId  : '4f55e1a6c2c7287814000001' }

and then search by the exact same string, it returns the document!

this.CalendarViewUser.findOne(
                    { OwnerID : '4f55e1a6c2c7287814000001'}
...

So I guess it is inserting some kind of garbage in the document’s OwnerID field, or there was some kind of incompatibility with the field’s Type. I will post the results.

  • 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-04T01:41:32+00:00Added an answer on June 4, 2026 at 1:41 am

    It turns out, the callback function of the FindCalendarViewUser function needed parenteses around itself… it works now, just by adding those parentesis…

    FindCalendarViewUser : function(Id){
        this.CalendarViewUser.findOne(
            { OwnerID : Id }, 
            (function(err,result){
    
                if(err) {console.log(err);}
                else{console.log(result);}  
            })
        );
    }
    

    Here’s the working example. Jesus christ why. I could have sworn I had used without that in other ocasions.

    EDIT: And now it is working without the parenteses. I’m sorry. It must be some tiny issue I have around the code. I just can’t find it.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
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.
In my XML file chapters tag has more chapter tag.i need to display chapters

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.