Object id shows as null

nodejs
mongodb

#1

Why are my ids showing as Null when I call them in mongo.
They do have an id when i see them in the data base but when i call them through the app they show as null.
console response:

Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own         promise library instead: http://mongoosejs.com/docs/promises.html
    { _id: 58c76e48f339ce0d322f59a5,
      name: 'bob',
      email: 'bob@bob.com',
      __v: 3,
      posts: [ null, null, null ] }

My code:

          post.create({                                        
              title:"working code",
            content:"Ive cracked this part"
        },function(post)    {                                  
            mongoose.model("user").findOne({name:"bob"},function(err,foundUser){ 

                if(err){console.log(err)}

                else{                                                  //if found push in the post that was created
                    foundUser.posts.push(post);
                    foundUser.save(function(err,saved){               //and save bobs new details
                    if(err)
                    {console.log(err)}
                    else
                    {console.log(saved)}

                }) 
          }
          })
          })

        mongoose.model("user").findOne({name:"bob"}).populate("posts").exec(function(err,user){
            if(err){console.log(err)}
        else{console.log(user, user.posts.id)}});

-----------I attach a post to a user once i find a user with name bob…
Here is bobs user schema

    var userSchema= new mongoose.Schema({
    name:String,
    email:String,
    posts:[{
        type:mongoose.Schema.Types.ObjectId,    //posts attribute looks for an id in a mongoose schema 
        ref:"post"                               // THe schema reference is post
            }]
    });

The IDs of these things do exist… but when I call them in the app they show as null…
why?


#2

I find use of the MongoDB internal ID key to be a little awkward.
When I have a repeating block of data items I usually create my own unique numbers to manipulate them.
The rules for existing matches can lead to new items being created if not careful. That will lead to a lot of
clean up which is also awkward in MongoDB. If you create your own keys I think its easier to maintain data.
That way you can get around the issues that generated unique identifiers have.


#3

Did you ever resolve this and/or find out the cause? I am having a very similar issue. The data fields will show in the app, but all id fields are null, even though they are not null in Mongo.